From 165f72fd222daa8f93a494cdad7d9ef66ffa20d1 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:52:35 +1300 Subject: [PATCH] API Deprecations for template layer (#11420) --- src/Forms/GridField/GridFieldDataColumns.php | 3 + src/View/SSTemplateParser.peg | 2 +- src/View/SSTemplateParser.php | 2 +- src/View/SSViewer.php | 81 ++++++++++++++++++-- src/View/SSViewer_DataPresenter.php | 4 +- src/View/SSViewer_FromString.php | 7 ++ src/View/SSViewer_Scope.php | 22 +++++- src/View/ThemeResourceLoader.php | 3 + src/View/ViewableData.php | 15 ++++ 9 files changed, 126 insertions(+), 13 deletions(-) diff --git a/src/Forms/GridField/GridFieldDataColumns.php b/src/Forms/GridField/GridFieldDataColumns.php index 41b0713d9..1bcb2ea4a 100644 --- a/src/Forms/GridField/GridFieldDataColumns.php +++ b/src/Forms/GridField/GridFieldDataColumns.php @@ -5,6 +5,7 @@ namespace SilverStripe\Forms\GridField; use SilverStripe\Core\Convert; use InvalidArgumentException; use LogicException; +use SilverStripe\Dev\Deprecation; use SilverStripe\View\ViewableData; /** @@ -228,9 +229,11 @@ class GridFieldDataColumns extends AbstractGridFieldComponent implements GridFie * @param ViewableData $record * @param string $columnName * @return string|null - returns null if it could not found a value + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it. */ protected function getValueFromRelation($record, $columnName) { + Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it.'); $fieldNameParts = explode('.', $columnName ?? ''); $tmpItem = clone($record); for ($idx = 0; $idx < sizeof($fieldNameParts ?? []); $idx++) { diff --git a/src/View/SSTemplateParser.peg b/src/View/SSTemplateParser.peg index 0f15460f9..76c40ed98 100644 --- a/src/View/SSTemplateParser.peg +++ b/src/View/SSTemplateParser.peg @@ -948,7 +948,7 @@ class SSTemplateParser extends Parser implements TemplateParser $arguments = $res['arguments']; // Note: 'type' here is important to disable subTemplates in SSViewer::getSubtemplateFor() - $res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getItem(), [' . + $res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getCurrentItem(), [' . implode(',', $arguments)."], \$scope, true);\n"; if ($this->includeDebuggingComments) { // Add include filename comments on dev sites diff --git a/src/View/SSTemplateParser.php b/src/View/SSTemplateParser.php index 9ca62eaa5..c7c273414 100644 --- a/src/View/SSTemplateParser.php +++ b/src/View/SSTemplateParser.php @@ -3897,7 +3897,7 @@ class SSTemplateParser extends Parser implements TemplateParser $arguments = $res['arguments']; // Note: 'type' here is important to disable subTemplates in SSViewer::getSubtemplateFor() - $res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getItem(), [' . + $res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getCurrentItem(), [' . implode(',', $arguments)."], \$scope, true);\n"; if ($this->includeDebuggingComments) { // Add include filename comments on dev sites diff --git a/src/View/SSViewer.php b/src/View/SSViewer.php index 3b82eb3fd..d8c142488 100644 --- a/src/View/SSViewer.php +++ b/src/View/SSViewer.php @@ -15,6 +15,7 @@ use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\Security\Permission; use InvalidArgumentException; +use SilverStripe\Dev\Deprecation; /** * Parses a template file with an *.ss file extension. @@ -86,6 +87,7 @@ class SSViewer implements Flushable * * @config * @var string + * @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine.global_key */ private static $global_key = '$CurrentReadingMode, $CurrentUser.ID'; @@ -134,6 +136,7 @@ class SSViewer implements Flushable * List of items being processed * * @var array + * @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine */ protected static $topLevel = []; @@ -141,6 +144,7 @@ class SSViewer implements Flushable * List of templates to select from * * @var array + * @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine */ protected $templates = null; @@ -148,6 +152,7 @@ class SSViewer implements Flushable * Absolute path to chosen template file * * @var string + * @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine */ protected $chosen = null; @@ -155,6 +160,7 @@ class SSViewer implements Flushable * Templates to use when looking up 'Layout' or 'Content' * * @var array + * @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine */ protected $subTemplates = []; @@ -165,11 +171,13 @@ class SSViewer implements Flushable /** * @var TemplateParser + * @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine */ protected $parser; /** * @var CacheInterface + * @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine */ protected $partialCacheStore = null; @@ -185,6 +193,7 @@ class SSViewer implements Flushable public function __construct($templates, TemplateParser $parser = null) { if ($parser) { + Deprecation::noticeWithNoReplacment('5.4.0', 'The $parser parameter is deprecated and will be removed'); $this->setParser($parser); } @@ -207,9 +216,11 @@ class SSViewer implements Flushable /** * Triggered early in the request when someone requests a flush. + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flush() */ public static function flush() { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flush()'); SSViewer::flush_template_cache(true); SSViewer::flush_cacheblock_cache(true); } @@ -220,9 +231,11 @@ class SSViewer implements Flushable * @param string $content The template content * @param bool|void $cacheTemplate Whether or not to cache the template from string * @return SSViewer + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString() */ public static function fromString($content, $cacheTemplate = null) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()'); $viewer = SSViewer_FromString::create($content); if ($cacheTemplate !== null) { $viewer->setCacheTemplate($cacheTemplate); @@ -325,9 +338,11 @@ class SSViewer implements Flushable * Get the current item being processed * * @return ViewableData + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it. */ public static function topLevel() { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); if (SSViewer::$topLevel) { return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1]; } @@ -385,9 +400,11 @@ class SSViewer implements Flushable /** * @param string|array $templates + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate() */ public function setTemplate($templates) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate()'); $this->templates = $templates; $this->chosen = $this->chooseTemplate($templates); $this->subTemplates = []; @@ -398,9 +415,11 @@ class SSViewer implements Flushable * * @param array|string $templates * @return string + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it */ public static function chooseTemplate($templates) { + Deprecation::noticeWithNoReplacment('5.4.0'); return ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes()); } @@ -408,9 +427,11 @@ class SSViewer implements Flushable * Set the template parser that will be used in template generation * * @param TemplateParser $parser + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setParser() */ public function setParser(TemplateParser $parser) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setParser()'); $this->parser = $parser; } @@ -418,9 +439,11 @@ class SSViewer implements Flushable * Returns the parser that is set for template generation * * @return TemplateParser + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getParser() */ public function getParser() { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getParser()'); if (!$this->parser) { $this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser')); } @@ -433,9 +456,11 @@ class SSViewer implements Flushable * @param array|string $templates * * @return bool + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::hasTemplate() */ public static function hasTemplate($templates) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::hasTemplate()'); return (bool)ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes()); } @@ -452,9 +477,11 @@ class SSViewer implements Flushable /** * @return string + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it */ public function exists() { + Deprecation::noticeWithNoReplacment('5.4.0'); return $this->chosen; } @@ -462,9 +489,11 @@ class SSViewer implements Flushable * @param string $identifier A template name without '.ss' extension or path * @param string $type The template type, either "main", "Includes" or "Layout" * @return string Full system path to a template file + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it */ public static function getTemplateFileByType($identifier, $type = null) { + Deprecation::noticeWithNoReplacment('5.4.0'); return ThemeResourceLoader::inst()->findTemplate(['type' => $type, $identifier], SSViewer::get_themes()); } @@ -475,9 +504,11 @@ class SSViewer implements Flushable * * @param bool $force Set this to true to force a re-flush. If left to false, flushing * may only be performed once a request. + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flushTemplateCache() */ public static function flush_template_cache($force = false) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flushTemplateCache()'); if (!SSViewer::$template_cache_flushed || $force) { $dir = dir(TEMP_PATH); while (false !== ($file = $dir->read())) { @@ -496,9 +527,11 @@ class SSViewer implements Flushable * * @param bool $force Set this to true to force a re-flush. If left to false, flushing * may only be performed once a request. + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flushCacheBlockCache() */ public static function flush_cacheblock_cache($force = false) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flushCacheBlockCache()'); if (!SSViewer::$cacheblock_cache_flushed || $force) { $cache = Injector::inst()->get(CacheInterface::class . '.cacheblock'); $cache->clear(); @@ -512,9 +545,11 @@ class SSViewer implements Flushable * Set the cache object to use when storing / retrieving partial cache blocks. * * @param CacheInterface $cache + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore() */ public function setPartialCacheStore($cache) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore()'); $this->partialCacheStore = $cache; } @@ -522,9 +557,11 @@ class SSViewer implements Flushable * Get the cache object to use when storing / retrieving partial cache blocks. * * @return CacheInterface + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore() */ public function getPartialCacheStore() { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore()'); if ($this->partialCacheStore) { return $this->partialCacheStore; } @@ -552,11 +589,13 @@ class SSViewer implements Flushable * @param ViewableData $item The item to use as the root scope for the template * @param array $overlay Any variables to layer on top of the scope * @param array $underlay Any variables to layer underneath the scope - * @param ViewableData $inheritedScope The current scope of a parent template including a sub-template + * @param SSViewer_Scope|null $inheritedScope The current scope of a parent template including a sub-template * @return string The result of executing the template + * @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::includeGeneratedTemplate() */ protected function includeGeneratedTemplate($cacheFile, $item, $overlay, $underlay, $inheritedScope = null) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::includeGeneratedTemplate()'); if (isset($_GET['showtemplate']) && $_GET['showtemplate'] && Permission::check('ADMIN')) { $lines = file($cacheFile ?? ''); echo "