Compare commits

...

9 Commits

Author SHA1 Message Date
Guy Sartorelli
96a889afec
Merge eefd0437fe into 615402d788 2024-10-22 09:04:58 +01:00
Steve Boyd
615402d788 Merge branch '5' into 6 2024-10-22 19:18:03 +13:00
github-actions
16cb2702af Merge branch '5.3' into 5 2024-10-22 05:33:36 +00:00
Guy Sartorelli
fe39a2a046
Merge pull request #11438 from creative-commoners/pulls/5.3/fix-unit-test
MNT Fix unit test
2024-10-22 18:32:46 +13:00
Steve Boyd
6df8732761 MNT Fix unit test 2024-10-22 17:56:01 +13:00
Guy Sartorelli
662ac9d1f9
Merge pull request #11432 from creative-commoners/pulls/6/fix-definemethods
MNT Fix unit tests
2024-10-22 16:25:32 +13:00
Steve Boyd
983e90b25e MNT Fix unit tests 2024-10-22 15:50:25 +13:00
Guy Sartorelli
8e08b1cf79
Merge branch '5' into 6
# Conflicts:
#	src/Forms/GridField/GridFieldDataColumns.php
#	src/Model/ModelData.php
#	src/View/SSViewer.php
#	src/View/SSViewer_DataPresenter.php
#	src/View/SSViewer_FromString.php
#	src/View/SSViewer_Scope.php
2024-10-22 13:04:29 +13:00
Guy Sartorelli
165f72fd22
API Deprecations for template layer (#11420) 2024-10-22 12:52:35 +13:00
13 changed files with 141 additions and 17 deletions

View File

@ -511,7 +511,7 @@ trait Extensible
// Setup all extension instances for this instance // Setup all extension instances for this instance
$this->extension_instances = []; $this->extension_instances = [];
foreach (ClassInfo::ancestry(static::class) as $class) { foreach (ClassInfo::ancestry(static::class) as $class) {
if (in_array($class, self::$unextendable_classes)) { if (in_array($class, self::class::$unextendable_classes)) {
continue; continue;
} }
$extensions = Config::inst()->get($class, 'extensions', Config::UNINHERITED | Config::EXCLUDE_EXTRA_SOURCES); $extensions = Config::inst()->get($class, 'extensions', Config::UNINHERITED | Config::EXCLUDE_EXTRA_SOURCES);

View File

@ -391,7 +391,7 @@ class Deprecation
} }
// Getting a backtrace is slow, so we only do it if we need it // Getting a backtrace is slow, so we only do it if we need it
$backtrace = null; $backtrace = [];
// Get the calling scope // Get the calling scope
if ($scope == Deprecation::SCOPE_METHOD) { if ($scope == Deprecation::SCOPE_METHOD) {

View File

@ -6,6 +6,7 @@ use SilverStripe\Core\Convert;
use InvalidArgumentException; use InvalidArgumentException;
use LogicException; use LogicException;
use SilverStripe\Model\ModelData; use SilverStripe\Model\ModelData;
use SilverStripe\Dev\Deprecation;
/** /**
* @see GridField * @see GridField
@ -228,9 +229,11 @@ class GridFieldDataColumns extends AbstractGridFieldComponent implements GridFie
* @param ModelData $record * @param ModelData $record
* @param string $columnName * @param string $columnName
* @return string|null - returns null if it could not found a value * @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) protected function getValueFromRelation($record, $columnName)
{ {
Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it.');
$fieldNameParts = explode('.', $columnName ?? ''); $fieldNameParts = explode('.', $columnName ?? '');
$tmpItem = clone($record); $tmpItem = clone($record);
for ($idx = 0; $idx < sizeof($fieldNameParts ?? []); $idx++) { for ($idx = 0; $idx < sizeof($fieldNameParts ?? []); $idx++) {

View File

@ -15,6 +15,7 @@ use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Debug; use SilverStripe\Dev\Debug;
use SilverStripe\Core\ArrayLib; use SilverStripe\Core\ArrayLib;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Model\List\ArrayList; use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\FieldType\DBHTMLText;
@ -385,9 +386,12 @@ class ModelData
/** /**
* Get the class name a field on this object will be casted to. * Get the class name a field on this object will be casted to.
*
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
*/ */
public function castingClass(string $field): string public function castingClass(string $field): string
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
// Strip arguments // Strip arguments
$spec = $this->castingHelper($field); $spec = $this->castingHelper($field);
return trim(strtok($spec ?? '', '(') ?? ''); return trim(strtok($spec ?? '', '(') ?? '');
@ -397,9 +401,11 @@ class ModelData
* Return the string-format type for the given field. * Return the string-format type for the given field.
* *
* @return string 'xml'|'raw' * @return string 'xml'|'raw'
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
*/ */
public function escapeTypeForField(string $field): string public function escapeTypeForField(string $field): string
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
$class = $this->castingClass($field) ?: $this->config()->get('default_cast'); $class = $this->castingClass($field) ?: $this->config()->get('default_cast');
/** @var DBField $type */ /** @var DBField $type */
@ -445,9 +451,11 @@ class ModelData
* @param string $fieldName Name of field * @param string $fieldName Name of field
* @param array $arguments List of optional arguments given * @param array $arguments List of optional arguments given
* @return string * @return string
* @deprecated 5.4.0 Will be made private
*/ */
protected function objCacheName($fieldName, $arguments) protected function objCacheName($fieldName, $arguments)
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be made private');
return $arguments return $arguments
? $fieldName . ":" . var_export($arguments, true) ? $fieldName . ":" . var_export($arguments, true)
: $fieldName; : $fieldName;
@ -506,6 +514,9 @@ class ModelData
bool $cache = false, bool $cache = false,
?string $cacheName = null ?string $cacheName = null
): ?object { ): ?object {
if ($cacheName !== null) {
Deprecation::noticeWithNoReplacment('5.4.0', 'The $cacheName parameter has been deprecated and will be removed');
}
$hasObj = false; $hasObj = false;
if (!$cacheName && $cache) { if (!$cacheName && $cache) {
$cacheName = $this->objCacheName($fieldName, $arguments); $cacheName = $this->objCacheName($fieldName, $arguments);
@ -569,9 +580,11 @@ class ModelData
* without re-running the method. * without re-running the method.
* *
* @return Object|DBField * @return Object|DBField
* @deprecated 5.4.0 use obj() instead
*/ */
public function cachedCall(string $fieldName, array $arguments = [], ?string $cacheName = null): object public function cachedCall(string $fieldName, array $arguments = [], ?string $cacheName = null): object
{ {
Deprecation::notice('5.4.0', 'Use obj() instead');
return $this->obj($fieldName, $arguments, true, $cacheName); return $this->obj($fieldName, $arguments, true, $cacheName);
} }
@ -591,9 +604,12 @@ class ModelData
/** /**
* Get the string value of a field on this object that has been suitable escaped to be inserted directly into a * Get the string value of a field on this object that has been suitable escaped to be inserted directly into a
* template. * template.
*
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/ */
public function XML_val(string $field, array $arguments = [], bool $cache = false): string public function XML_val(string $field, array $arguments = [], bool $cache = false): string
{ {
Deprecation::noticeWithNoReplacment('5.4.0');
$result = $this->obj($field, $arguments, $cache); $result = $this->obj($field, $arguments, $cache);
if (!$result) { if (!$result) {
return ''; return '';
@ -606,9 +622,11 @@ class ModelData
* Get an array of XML-escaped values by field name * Get an array of XML-escaped values by field name
* *
* @param array $fields an array of field names * @param array $fields an array of field names
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/ */
public function getXMLValues(array $fields): array public function getXMLValues(array $fields): array
{ {
Deprecation::noticeWithNoReplacment('5.4.0');
$result = []; $result = [];
foreach ($fields as $field) { foreach ($fields as $field) {

View File

@ -948,7 +948,7 @@ class SSTemplateParser extends Parser implements TemplateParser
$arguments = $res['arguments']; $arguments = $res['arguments'];
// Note: 'type' here is important to disable subTemplates in SSViewer::getSubtemplateFor() // 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"; implode(',', $arguments)."], \$scope, true);\n";
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites if ($this->includeDebuggingComments) { // Add include filename comments on dev sites

View File

@ -3897,7 +3897,7 @@ class SSTemplateParser extends Parser implements TemplateParser
$arguments = $res['arguments']; $arguments = $res['arguments'];
// Note: 'type' here is important to disable subTemplates in SSViewer::getSubtemplateFor() // 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"; implode(',', $arguments)."], \$scope, true);\n";
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites if ($this->includeDebuggingComments) { // Add include filename comments on dev sites

View File

@ -16,6 +16,7 @@ use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use InvalidArgumentException; use InvalidArgumentException;
use SilverStripe\Model\ModelData; use SilverStripe\Model\ModelData;
use SilverStripe\Dev\Deprecation;
/** /**
* Parses a template file with an *.ss file extension. * Parses a template file with an *.ss file extension.
@ -87,6 +88,7 @@ class SSViewer implements Flushable
* *
* @config * @config
* @var string * @var string
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine.global_key
*/ */
private static $global_key = '$CurrentReadingMode, $CurrentUser.ID'; private static $global_key = '$CurrentReadingMode, $CurrentUser.ID';
@ -135,6 +137,7 @@ class SSViewer implements Flushable
* List of items being processed * List of items being processed
* *
* @var array * @var array
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
*/ */
protected static $topLevel = []; protected static $topLevel = [];
@ -142,6 +145,7 @@ class SSViewer implements Flushable
* List of templates to select from * List of templates to select from
* *
* @var array * @var array
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
*/ */
protected $templates = null; protected $templates = null;
@ -149,6 +153,7 @@ class SSViewer implements Flushable
* Absolute path to chosen template file * Absolute path to chosen template file
* *
* @var string * @var string
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
*/ */
protected $chosen = null; protected $chosen = null;
@ -156,6 +161,7 @@ class SSViewer implements Flushable
* Templates to use when looking up 'Layout' or 'Content' * Templates to use when looking up 'Layout' or 'Content'
* *
* @var array * @var array
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
*/ */
protected $subTemplates = []; protected $subTemplates = [];
@ -166,11 +172,13 @@ class SSViewer implements Flushable
/** /**
* @var TemplateParser * @var TemplateParser
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
*/ */
protected $parser; protected $parser;
/** /**
* @var CacheInterface * @var CacheInterface
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
*/ */
protected $partialCacheStore = null; protected $partialCacheStore = null;
@ -186,6 +194,7 @@ class SSViewer implements Flushable
public function __construct($templates, TemplateParser $parser = null) public function __construct($templates, TemplateParser $parser = null)
{ {
if ($parser) { if ($parser) {
Deprecation::noticeWithNoReplacment('5.4.0', 'The $parser parameter is deprecated and will be removed');
$this->setParser($parser); $this->setParser($parser);
} }
@ -208,9 +217,11 @@ class SSViewer implements Flushable
/** /**
* Triggered early in the request when someone requests a flush. * 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() public static function flush()
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flush()');
SSViewer::flush_template_cache(true); SSViewer::flush_template_cache(true);
SSViewer::flush_cacheblock_cache(true); SSViewer::flush_cacheblock_cache(true);
} }
@ -221,9 +232,11 @@ class SSViewer implements Flushable
* @param string $content The template content * @param string $content The template content
* @param bool|void $cacheTemplate Whether or not to cache the template from string * @param bool|void $cacheTemplate Whether or not to cache the template from string
* @return SSViewer * @return SSViewer
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()
*/ */
public static function fromString($content, $cacheTemplate = null) 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); $viewer = SSViewer_FromString::create($content);
if ($cacheTemplate !== null) { if ($cacheTemplate !== null) {
$viewer->setCacheTemplate($cacheTemplate); $viewer->setCacheTemplate($cacheTemplate);
@ -326,9 +339,11 @@ class SSViewer implements Flushable
* Get the current item being processed * Get the current item being processed
* *
* @return ModelData * @return ModelData
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
*/ */
public static function topLevel() public static function topLevel()
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
if (SSViewer::$topLevel) { if (SSViewer::$topLevel) {
return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1]; return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1];
} }
@ -386,9 +401,11 @@ class SSViewer implements Flushable
/** /**
* @param string|array $templates * @param string|array $templates
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate()
*/ */
public function setTemplate($templates) public function setTemplate($templates)
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate()');
$this->templates = $templates; $this->templates = $templates;
$this->chosen = $this->chooseTemplate($templates); $this->chosen = $this->chooseTemplate($templates);
$this->subTemplates = []; $this->subTemplates = [];
@ -399,9 +416,11 @@ class SSViewer implements Flushable
* *
* @param array|string $templates * @param array|string $templates
* @return string * @return string
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/ */
public static function chooseTemplate($templates) public static function chooseTemplate($templates)
{ {
Deprecation::noticeWithNoReplacment('5.4.0');
return ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes()); return ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
} }
@ -409,9 +428,11 @@ class SSViewer implements Flushable
* Set the template parser that will be used in template generation * Set the template parser that will be used in template generation
* *
* @param TemplateParser $parser * @param TemplateParser $parser
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setParser()
*/ */
public function setParser(TemplateParser $parser) public function setParser(TemplateParser $parser)
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setParser()');
$this->parser = $parser; $this->parser = $parser;
} }
@ -419,9 +440,11 @@ class SSViewer implements Flushable
* Returns the parser that is set for template generation * Returns the parser that is set for template generation
* *
* @return TemplateParser * @return TemplateParser
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getParser()
*/ */
public function getParser() public function getParser()
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getParser()');
if (!$this->parser) { if (!$this->parser) {
$this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser')); $this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser'));
} }
@ -434,9 +457,11 @@ class SSViewer implements Flushable
* @param array|string $templates * @param array|string $templates
* *
* @return bool * @return bool
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::hasTemplate()
*/ */
public static function hasTemplate($templates) 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()); return (bool)ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
} }
@ -453,9 +478,11 @@ class SSViewer implements Flushable
/** /**
* @return string * @return string
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/ */
public function exists() public function exists()
{ {
Deprecation::noticeWithNoReplacment('5.4.0');
return $this->chosen; return $this->chosen;
} }
@ -463,9 +490,11 @@ class SSViewer implements Flushable
* @param string $identifier A template name without '.ss' extension or path * @param string $identifier A template name without '.ss' extension or path
* @param string $type The template type, either "main", "Includes" or "Layout" * @param string $type The template type, either "main", "Includes" or "Layout"
* @return string Full system path to a template file * @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) public static function getTemplateFileByType($identifier, $type = null)
{ {
Deprecation::noticeWithNoReplacment('5.4.0');
return ThemeResourceLoader::inst()->findTemplate(['type' => $type, $identifier], SSViewer::get_themes()); return ThemeResourceLoader::inst()->findTemplate(['type' => $type, $identifier], SSViewer::get_themes());
} }
@ -476,9 +505,11 @@ class SSViewer implements Flushable
* *
* @param bool $force Set this to true to force a re-flush. If left to false, flushing * @param bool $force Set this to true to force a re-flush. If left to false, flushing
* may only be performed once a request. * 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) 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) { if (!SSViewer::$template_cache_flushed || $force) {
$dir = dir(TEMP_PATH); $dir = dir(TEMP_PATH);
while (false !== ($file = $dir->read())) { while (false !== ($file = $dir->read())) {
@ -497,9 +528,11 @@ class SSViewer implements Flushable
* *
* @param bool $force Set this to true to force a re-flush. If left to false, flushing * @param bool $force Set this to true to force a re-flush. If left to false, flushing
* may only be performed once a request. * 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) 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) { if (!SSViewer::$cacheblock_cache_flushed || $force) {
$cache = Injector::inst()->get(CacheInterface::class . '.cacheblock'); $cache = Injector::inst()->get(CacheInterface::class . '.cacheblock');
$cache->clear(); $cache->clear();
@ -513,9 +546,11 @@ class SSViewer implements Flushable
* Set the cache object to use when storing / retrieving partial cache blocks. * Set the cache object to use when storing / retrieving partial cache blocks.
* *
* @param CacheInterface $cache * @param CacheInterface $cache
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore()
*/ */
public function setPartialCacheStore($cache) public function setPartialCacheStore($cache)
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore()');
$this->partialCacheStore = $cache; $this->partialCacheStore = $cache;
} }
@ -523,9 +558,11 @@ class SSViewer implements Flushable
* Get the cache object to use when storing / retrieving partial cache blocks. * Get the cache object to use when storing / retrieving partial cache blocks.
* *
* @return CacheInterface * @return CacheInterface
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore()
*/ */
public function getPartialCacheStore() public function getPartialCacheStore()
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore()');
if ($this->partialCacheStore) { if ($this->partialCacheStore) {
return $this->partialCacheStore; return $this->partialCacheStore;
} }
@ -553,11 +590,13 @@ class SSViewer implements Flushable
* @param ModelData $item The item to use as the root scope for the template * @param ModelData $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 $overlay Any variables to layer on top of the scope
* @param array $underlay Any variables to layer underneath the scope * @param array $underlay Any variables to layer underneath the scope
* @param ModelData $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 * @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) 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')) { if (isset($_GET['showtemplate']) && $_GET['showtemplate'] && Permission::check('ADMIN')) {
$lines = file($cacheFile ?? ''); $lines = file($cacheFile ?? '');
echo "<h2>Template: $cacheFile</h2>"; echo "<h2>Template: $cacheFile</h2>";
@ -597,6 +636,9 @@ class SSViewer implements Flushable
*/ */
public function process($item, $arguments = null, $inheritedScope = null) public function process($item, $arguments = null, $inheritedScope = null)
{ {
if ($inheritedScope !== null) {
Deprecation::noticeWithNoReplacment('5.4.0', 'The $inheritedScope parameter is deprecated and will be removed');
}
// Set hashlinks and temporarily modify global state // Set hashlinks and temporarily modify global state
$rewrite = $this->getRewriteHashLinks(); $rewrite = $this->getRewriteHashLinks();
$origRewriteDefault = static::getRewriteHashLinksDefault(); $origRewriteDefault = static::getRewriteHashLinksDefault();
@ -683,9 +725,11 @@ PHP;
* @param string $subtemplate Sub-template to use * @param string $subtemplate Sub-template to use
* *
* @return array|null * @return array|null
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getSubtemplateFor()
*/ */
protected function getSubtemplateFor($subtemplate) protected function getSubtemplateFor($subtemplate)
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getSubtemplateFor()');
// Get explicit subtemplate name // Get explicit subtemplate name
if (isset($this->subTemplates[$subtemplate])) { if (isset($this->subTemplates[$subtemplate])) {
return $this->subTemplates[$subtemplate]; return $this->subTemplates[$subtemplate];
@ -723,9 +767,14 @@ PHP;
* @param bool $globalRequirements * @param bool $globalRequirements
* *
* @return string Evaluated result * @return string Evaluated result
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::execute_template()
*/ */
public static function execute_template($template, $data, $arguments = null, $scope = null, $globalRequirements = false) public static function execute_template($template, $data, $arguments = null, $scope = null, $globalRequirements = false)
{ {
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be replaced with SilverStripe\View\SSTemplateEngine::execute_template()'
);
$v = SSViewer::create($template); $v = SSViewer::create($template);
if ($globalRequirements) { if ($globalRequirements) {
@ -755,9 +804,11 @@ PHP;
* @param bool $globalRequirements * @param bool $globalRequirements
* *
* @return string Evaluated result * @return string Evaluated result
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()
*/ */
public static function execute_string($content, $data, $arguments = null, $globalRequirements = false) public static function execute_string($content, $data, $arguments = null, $globalRequirements = false)
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()');
$v = SSViewer::fromString($content); $v = SSViewer::fromString($content);
if ($globalRequirements) { if ($globalRequirements) {
@ -782,9 +833,11 @@ PHP;
* @param string $content The template contents * @param string $content The template contents
* @param string $template The template file name * @param string $template The template file name
* @return string * @return string
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::parseTemplateContent()
*/ */
public function parseTemplateContent($content, $template = "") public function parseTemplateContent($content, $template = "")
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::parseTemplateContent()');
return $this->getParser()->compileString( return $this->getParser()->compileString(
$content, $content,
$template, $template,
@ -797,18 +850,22 @@ PHP;
* 'Content' & 'Layout', and will have to contain 'main' * 'Content' & 'Layout', and will have to contain 'main'
* *
* @return array * @return array
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/ */
public function templates() public function templates()
{ {
Deprecation::noticeWithNoReplacment('5.4.0');
return array_merge(['main' => $this->chosen], $this->subTemplates); return array_merge(['main' => $this->chosen], $this->subTemplates);
} }
/** /**
* @param string $type "Layout" or "main" * @param string $type "Layout" or "main"
* @param string $file Full system path to the template file * @param string $file Full system path to the template file
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/ */
public function setTemplateFile($type, $file) public function setTemplateFile($type, $file)
{ {
Deprecation::noticeWithNoReplacment('5.4.0');
if (!$type || $type == 'main') { if (!$type || $type == 'main') {
$this->chosen = $file; $this->chosen = $file;
} else { } else {
@ -823,17 +880,29 @@ PHP;
* @param string $contentGeneratedSoFar The content of the template generated so far; it should contain * @param string $contentGeneratedSoFar The content of the template generated so far; it should contain
* the DOCTYPE declaration. * the DOCTYPE declaration.
* @return string * @return string
* @deprecated 5.4.0 Use getBaseTag() instead
*/ */
public static function get_base_tag($contentGeneratedSoFar) public static function get_base_tag($contentGeneratedSoFar)
{
Deprecation::notice('5.4.0', 'Use getBaseTag() instead');
// Is the document XHTML?
$isXhtml = preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar ?? '');
return static::getBaseTag($isXhtml);
}
/**
* Return an appropriate base tag for the given template.
* It will be closed on an XHTML document, and unclosed on an HTML document.
*
* @param bool $isXhtml Whether the DOCTYPE is xhtml or not.
*/
public static function getBaseTag(bool $isXhtml = false): string
{ {
// Base href should always have a trailing slash // Base href should always have a trailing slash
$base = rtrim(Director::absoluteBaseURL(), '/') . '/'; $base = rtrim(Director::absoluteBaseURL(), '/') . '/';
if ($isXhtml) {
// Is the document XHTML?
if (preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar ?? '')) {
return "<base href=\"$base\" />"; return "<base href=\"$base\" />";
} else {
return "<base href=\"$base\"><!--[if lte IE 6]></base><![endif]-->";
} }
return "<base href=\"$base\"><!--[if lte IE 6]></base><![endif]-->";
} }
} }

View File

@ -6,6 +6,7 @@ use InvalidArgumentException;
use SilverStripe\Core\ClassInfo; use SilverStripe\Core\ClassInfo;
use SilverStripe\Model\ModelData; use SilverStripe\Model\ModelData;
use SilverStripe\Model\List\ArrayList; use SilverStripe\Model\List\ArrayList;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBField;
/** /**
@ -13,7 +14,7 @@ use SilverStripe\ORM\FieldType\DBField;
* data that is scope-independant (like BaseURL), or type-specific data that is layered on top cross-cut like * data that is scope-independant (like BaseURL), or type-specific data that is layered on top cross-cut like
* (like $FirstLast etc). * (like $FirstLast etc).
* *
* It's separate from SSViewer_Scope to keep that fairly complex code as clean as possible. * @deprecated 5.4.0 Will be merged into SilverStripe\View\SSViewer_Scope
*/ */
class SSViewer_DataPresenter extends SSViewer_Scope class SSViewer_DataPresenter extends SSViewer_Scope
{ {
@ -67,6 +68,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope
array $underlay = null, array $underlay = null,
SSViewer_Scope $inheritedScope = null SSViewer_Scope $inheritedScope = null
) { ) {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be merged into ' . SSViewer_Scope::class, Deprecation::SCOPE_CLASS);
parent::__construct($item, $inheritedScope); parent::__construct($item, $inheritedScope);
$this->overlay = $overlay ?: []; $this->overlay = $overlay ?: [];

View File

@ -4,9 +4,11 @@ namespace SilverStripe\View;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Dev\Deprecation;
/** /**
* Special SSViewer that will process a template passed as a string, rather than a filename. * Special SSViewer that will process a template passed as a string, rather than a filename.
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()
*/ */
class SSViewer_FromString extends SSViewer class SSViewer_FromString extends SSViewer
{ {
@ -38,6 +40,11 @@ class SSViewer_FromString extends SSViewer
*/ */
public function __construct($content, TemplateParser $parser = null) public function __construct($content, TemplateParser $parser = null)
{ {
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()',
Deprecation::SCOPE_CLASS
);
if ($parser) { if ($parser) {
$this->setParser($parser); $this->setParser($parser);
} }

View File

@ -6,6 +6,7 @@ use ArrayIterator;
use Countable; use Countable;
use Iterator; use Iterator;
use SilverStripe\Model\List\ArrayList; use SilverStripe\Model\List\ArrayList;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBBoolean; use SilverStripe\ORM\FieldType\DBBoolean;
use SilverStripe\ORM\FieldType\DBText; use SilverStripe\ORM\FieldType\DBText;
use SilverStripe\ORM\FieldType\DBFloat; use SilverStripe\ORM\FieldType\DBFloat;
@ -124,9 +125,11 @@ class SSViewer_Scope
* Returns the current "active" item * Returns the current "active" item
* *
* @return object * @return object
* @deprecated 5.4.0 use getCurrentItem() instead.
*/ */
public function getItem() public function getItem()
{ {
Deprecation::notice('5.4.0', 'use getCurrentItem() instead.');
$item = $this->itemIterator ? $this->itemIterator->current() : $this->item; $item = $this->itemIterator ? $this->itemIterator->current() : $this->item;
if (is_scalar($item)) { if (is_scalar($item)) {
$item = $this->convertScalarToDBField($item); $item = $this->convertScalarToDBField($item);
@ -140,6 +143,11 @@ class SSViewer_Scope
return $item; return $item;
} }
public function getCurrentItem()
{
return $this->getItem();
}
/** /**
* Called at the start of every lookup chain by SSTemplateParser to indicate a new lookup from local scope * Called at the start of every lookup chain by SSTemplateParser to indicate a new lookup from local scope
* *
@ -192,7 +200,7 @@ class SSViewer_Scope
*/ */
public function getObj($name, $arguments = [], $cache = false, $cacheName = null) public function getObj($name, $arguments = [], $cache = false, $cacheName = null)
{ {
$on = $this->getItem(); $on = $this->getCurrentItem();
if ($on === null) { if ($on === null) {
return null; return null;
} }
@ -205,9 +213,11 @@ class SSViewer_Scope
* @param bool $cache * @param bool $cache
* @param string $cacheName * @param string $cacheName
* @return $this * @return $this
* @deprecated 5.4.0 Will be renamed scopeToIntermediateValue()
*/ */
public function obj($name, $arguments = [], $cache = false, $cacheName = null) public function obj($name, $arguments = [], $cache = false, $cacheName = null)
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed scopeToIntermediateValue()');
switch ($name) { switch ($name) {
case 'Up': case 'Up':
if ($this->upIndex === null) { if ($this->upIndex === null) {
@ -259,7 +269,7 @@ class SSViewer_Scope
*/ */
public function self() public function self()
{ {
$result = $this->getItem(); $result = $this->getCurrentItem();
$this->resetLocalScope(); $this->resetLocalScope();
return $result; return $result;
@ -359,8 +369,12 @@ class SSViewer_Scope
*/ */
public function __call($name, $arguments) public function __call($name, $arguments)
{ {
$on = $this->getItem(); $on = $this->getCurrentItem();
$retval = $on ? $on->$name(...$arguments) : null; if ($on instanceof ViewableData && $name === 'XML_val') {
$retval = $on->XML_val(...$arguments);
} else {
$retval = $on ? $on->$name(...$arguments) : null;
}
$this->resetLocalScope(); $this->resetLocalScope();
return $retval; return $retval;

View File

@ -9,6 +9,7 @@ use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Manifest\ModuleLoader; use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Core\Manifest\ModuleResourceLoader;
use SilverStripe\Core\Path; use SilverStripe\Core\Path;
use SilverStripe\Dev\Deprecation;
/** /**
* Handles finding templates from a stack of template manifest objects. * Handles finding templates from a stack of template manifest objects.
@ -182,9 +183,11 @@ class ThemeResourceLoader implements Flushable, TemplateGlobalProvider
* @return string Absolute path to resolved template file, or null if not resolved. * @return string Absolute path to resolved template file, or null if not resolved.
* File location will be in the format themes/<theme>/templates/<directories>/<type>/<basename>.ss * File location will be in the format themes/<theme>/templates/<directories>/<type>/<basename>.ss
* Note that type (e.g. 'Layout') is not the root level directory under 'templates'. * Note that type (e.g. 'Layout') is not the root level directory under 'templates'.
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
*/ */
public function findTemplate($template, $themes = null) public function findTemplate($template, $themes = null)
{ {
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
if ($themes === null) { if ($themes === null) {
$themes = SSViewer::get_themes(); $themes = SSViewer::get_themes();
} }

View File

@ -111,8 +111,8 @@ class DeprecationTest extends SapphireTest
'Will be removed without equivalent functionality to replace it.', 'Will be removed without equivalent functionality to replace it.',
'Called from SilverStripe\Dev\Tests\DeprecationTest->testNoticeNoReplacement.' 'Called from SilverStripe\Dev\Tests\DeprecationTest->testNoticeNoReplacement.'
]); ]);
$this->expectDeprecation(); $this->expectException(DeprecationTestException::class);
$this->expectDeprecationMessage($message); $this->expectExceptionMessage($message);
$this->enableDeprecationNotices(true); $this->enableDeprecationNotices(true);
$ret = $this->myDeprecatedMethodNoReplacement(); $ret = $this->myDeprecatedMethodNoReplacement();
$this->assertSame('abc', $ret); $this->assertSame('abc', $ret);

View File

@ -32,6 +32,14 @@ class VersionedMemberAuthenticatorTest extends SapphireTest
// Remove password validation // Remove password validation
Member::set_password_validator(null); Member::set_password_validator(null);
// Explicity add the Versioned extension to Member, even though it's already in $required_extensions.
// This is done to call `unset(self::class::$extra_methods[strtolower($subclass)]);` in
// Extensible::add_extension() so when CustomMethods::getExtraMethodConfig() updates the $extra_methods
// it will include methods of Versioned such as publishSingle()
// This issue will only occur when running subsequent unit test classes in the same process, rather than this
// this unit test class in isolation
Member::add_extension(Versioned::class);
} }
protected function tearDown(): void protected function tearDown(): void