mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW Allow SSViewer and SSViewer_FromString to be injectable
This commit is contained in:
parent
243304c633
commit
823e49526f
@ -414,7 +414,7 @@ class Controller extends RequestHandler implements TemplateGlobalProvider
|
||||
$templates = array_unique(array_merge($actionTemplates, $classTemplates));
|
||||
}
|
||||
|
||||
return new SSViewer($templates);
|
||||
return SSViewer::create($templates);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1582,7 +1582,7 @@ class Form extends ViewableData implements HasRequestHandler
|
||||
*/
|
||||
public function forAjaxTemplate()
|
||||
{
|
||||
$view = new SSViewer($this->getTemplates());
|
||||
$view = SSViewer::create($this->getTemplates());
|
||||
|
||||
$return = $view->dontRewriteHashlinks()->process($this);
|
||||
|
||||
@ -1631,7 +1631,7 @@ class Form extends ViewableData implements HasRequestHandler
|
||||
));
|
||||
|
||||
if (is_string($template)) {
|
||||
$template = new SSViewer($template);
|
||||
$template = SSViewer::create($template);
|
||||
}
|
||||
|
||||
return $template->process($custom);
|
||||
|
@ -8,6 +8,7 @@ use Psr\SimpleCache\CacheInterface;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Flushable;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Core\Injector\Injectable;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
@ -40,6 +41,7 @@ use InvalidArgumentException;
|
||||
class SSViewer implements Flushable
|
||||
{
|
||||
use Configurable;
|
||||
use Injectable;
|
||||
|
||||
/**
|
||||
* Identifier for the default theme
|
||||
@ -65,17 +67,17 @@ class SSViewer implements Flushable
|
||||
/**
|
||||
* @var array $templates List of templates to select from
|
||||
*/
|
||||
private $templates = null;
|
||||
protected $templates = null;
|
||||
|
||||
/**
|
||||
* @var string $chosen Absolute path to chosen template file
|
||||
*/
|
||||
private $chosen = null;
|
||||
protected $chosen = null;
|
||||
|
||||
/**
|
||||
* @var array Templates to use when looking up 'Layout' or 'Content'
|
||||
*/
|
||||
private $subTemplates = null;
|
||||
protected $subTemplates = null;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
@ -143,7 +145,7 @@ class SSViewer implements Flushable
|
||||
*/
|
||||
public static function fromString($content, $cacheTemplate = null)
|
||||
{
|
||||
$viewer = new SSViewer_FromString($content);
|
||||
$viewer = SSViewer_FromString::create($content);
|
||||
if ($cacheTemplate !== null) {
|
||||
$viewer->setCacheTemplate($cacheTemplate);
|
||||
}
|
||||
@ -574,7 +576,7 @@ class SSViewer implements Flushable
|
||||
*/
|
||||
public static function execute_template($template, $data, $arguments = null, $scope = null)
|
||||
{
|
||||
$v = new SSViewer($template);
|
||||
$v = SSViewer::create($template);
|
||||
$v->includeRequirements(false);
|
||||
|
||||
return $v->process($data, $arguments, $scope);
|
||||
|
@ -56,7 +56,7 @@ class SSViewer_FromString extends SSViewer
|
||||
if ($this->cacheTemplate !== null) {
|
||||
$cacheTemplate = $this->cacheTemplate;
|
||||
} else {
|
||||
$cacheTemplate = Config::inst()->get('SilverStripe\\View\\SSViewer_FromString', 'cache_template');
|
||||
$cacheTemplate = static::config()->get('cache_template');
|
||||
}
|
||||
|
||||
if (!$cacheTemplate) {
|
||||
|
@ -382,7 +382,7 @@ class ViewableData implements IteratorAggregate
|
||||
public function renderWith($template, $customFields = null)
|
||||
{
|
||||
if (!is_object($template)) {
|
||||
$template = new SSViewer($template);
|
||||
$template = SSViewer::create($template);
|
||||
}
|
||||
|
||||
$data = $this->getCustomisedObj() ?: $this;
|
||||
|
Loading…
Reference in New Issue
Block a user