diff --git a/src/Control/Controller.php b/src/Control/Controller.php index 0a7233703..f367fc57f 100644 --- a/src/Control/Controller.php +++ b/src/Control/Controller.php @@ -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); } /** diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 1aa74cfb4..0da09cbd6 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -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); diff --git a/src/View/SSViewer.php b/src/View/SSViewer.php index 3cde50277..f49ad4738 100644 --- a/src/View/SSViewer.php +++ b/src/View/SSViewer.php @@ -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); diff --git a/src/View/SSViewer_FromString.php b/src/View/SSViewer_FromString.php index f9a8f8d3e..653947cbf 100644 --- a/src/View/SSViewer_FromString.php +++ b/src/View/SSViewer_FromString.php @@ -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) { diff --git a/src/View/ViewableData.php b/src/View/ViewableData.php index 5f372c022..e62e852f8 100644 --- a/src/View/ViewableData.php +++ b/src/View/ViewableData.php @@ -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;