-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Deprecations for template layer #11420
API Deprecations for template layer #11420
Conversation
63b99cc
to
044d44b
Compare
@@ -228,16 +229,18 @@ public function getColumnMetadata($gridField, $column) | |||
* @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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this method just isn't used at all. It used to be used in getColumnContent()
but the work this method used to do is now offloaded to GridField::getDataFieldValue()
.
Found this because it's the only usage of XML_val()
in core.
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine.global_key | ||
*/ | ||
private static $global_key = '$CurrentReadingMode, $CurrentUser.ID'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whole bunch of stuff like this that's template-specific which is getting moved over to the new engine.
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine | ||
*/ | ||
protected static $topLevel = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really have a policy about what to do with properties - I've opted to deprecate it but didn't bother mentioning it in the docs
src/View/SSViewer.php
Outdated
public function exists() | ||
{ | ||
Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it'); | ||
return $this->chosen; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Literally nothing called this (except I think one place inside SSViewer itself)
return $this->chosen; | ||
} | ||
|
||
/** | ||
* @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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't called anywhere - and ideally people will refer to templates more loosely as candidates rather than caring about the specific files. What are you ever going to do with a full template file path in code if you're not a template rendering engine?
* @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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a PHPDoc so doesn't break anything to change this - and I'm changing it to what is actually being passed in here.
@@ -796,18 +865,22 @@ public function parseTemplateContent($content, $template = "") | |||
* 'Content' & 'Layout', and will have to contain 'main' | |||
* | |||
* @return array | |||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it | |||
*/ | |||
public function templates() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Literally one place called this and it was a unit test.
return array_merge(['main' => $this->chosen], $this->subTemplates); | ||
} | ||
|
||
/** | ||
* @param string $type "Layout" or "main" | ||
* @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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing called this so we clearly don't need to replace it in the new engine.
@@ -822,17 +895,29 @@ public function setTemplateFile($type, $file) | |||
* @param string $contentGeneratedSoFar The content of the template generated so far; it should contain | |||
* the DOCTYPE declaration. | |||
* @return string | |||
* @deprecated 5.4.0 Use getBaseTag() instead | |||
*/ | |||
public static function get_base_tag($contentGeneratedSoFar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming this, and passing in a boolean so it's easier to use by other engines.
But for now our template parser will keep calling this (hence why it's suppressed). I've opted to not add Deprecation::withSuppressedNotice()
anywhere inside the template parser, so anything that calls has a suppressed notice directly in the method being called.
* | ||
* @param bool $isXhtml Whether the DOCTYPE is xhtml or not. | ||
*/ | ||
public static function getBaseTag(bool $isXhtml = false): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For simple methods like this it makes sense to implement in 5.4 so people can swap to it directly if they were calling it in their code.
* 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this was intentionally kept separate, but whatever the case was when that decision was made it was causing me headaches trying to sort out what the difference is between SSViewer_Scope
and this class. Especially since they have a lot of similar logic in them - the __call()
class is a great example where the code flow is not obvious with this class split out like this.
I've opted to merge the two classes together, and simplify where I can. There are or will be additional cards to simplify it further in the future, too.
|
||
/** | ||
* 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't make sense to have this abstraction anymore - if you have a template string, it'll be for a specific template syntax so you should make sure to get the correct template engine from the injector and ask it to render your template string directly.
* @deprecated 5.4.0 use getCurrentItem() instead. | ||
*/ | ||
public function getItem() | ||
{ | ||
Deprecation::notice('5.4.0', 'use getCurrentItem() instead.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just renamed it to be a little clearer that it's not just getting the value of the item
property. I ran into problems when I tried to replace all instances of $this->item
with calling this method, because sometimes that's not what this method returns.
* @deprecated 5.4.0 Will be renamed scopeToIntermediateValue() | ||
*/ | ||
public function obj($name, $arguments = [], $cache = false, $cacheName = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting renamed so it's clear what it's for
@@ -182,9 +183,11 @@ public function getPath($identifier) | |||
* @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 | |||
* 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't make sense for this to be here anymore, since this only knows about ss templates.
There is a replacement method for this in the new engine but I've opted to keep it private, to dissuade people from trying to deal with file paths for templates - we should be thinking and talking about template files as template "candidates" instead, i.e. "render with Includes/Header
" and let the template engine figure out through theme inheritance which exact template file that maps to.
@@ -426,9 +426,11 @@ public function castingHelper($field) | |||
* | |||
* @param string $field | |||
* @return string | |||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it. | |||
*/ | |||
public function castingClass($field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing uses this, so no need to replace it. If we do need this in the future it can be added to the new CastingService
.
@@ -439,10 +441,13 @@ public function castingClass($field) | |||
* | |||
* @param string $field | |||
* @return string 'xml'|'raw' | |||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it. | |||
*/ | |||
public function escapeTypeForField($field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one use of this in core, so no need to replace it. If we do need this in the future it can be added to the new CastingService
.
@@ -488,9 +493,11 @@ public function renderWith($template, $customFields = null) | |||
* @param string $fieldName Name of field | |||
* @param array $arguments List of optional arguments given | |||
* @return string | |||
* @deprecated 5.4.0 Will be made private | |||
*/ | |||
protected function objCacheName($fieldName, $arguments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll see in the implementations for objCacheGet
and objCacheSet
that they call this directly now, so there's no need for anyone else to be calling it.
src/View/ViewableData.php
Outdated
if ($cacheName !== null) { | ||
Deprecation::notice('5.4.0', 'The $cacheName parameter has been deprecated and will be removed'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That param was never used, and it's easier to reason about the cache if the cache name is always derived from the field name and arguments.
@@ -588,9 +598,11 @@ public function obj($fieldName, $arguments = [], $cache = false, $cacheName = nu | |||
* @param array $arguments | |||
* @param string $identifier an optional custom cache identifier | |||
* @return Object|DBField | |||
* @deprecated 5.4.0 use obj() instead | |||
*/ | |||
public function cachedCall($fieldName, $arguments = [], $identifier = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing uses this, and if they did they should just call obj()
directly instead.
@@ -617,9 +629,11 @@ public function hasValue($field, $arguments = [], $cache = true) | |||
* @param array $arguments | |||
* @param bool $cache | |||
* @return string | |||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it | |||
*/ | |||
public function XML_val($field, $arguments = [], $cache = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently called directly from SSViewer_Scope
- that will be calling methods on ViewLayerData
now instead, and the methods on ViewLayerData
don't rely on this method, so there's no need to keep it.
@@ -630,13 +644,14 @@ public function XML_val($field, $arguments = [], $cache = false) | |||
* | |||
* @param array $fields an array of field names | |||
* @return array | |||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it | |||
*/ | |||
public function getXMLValues($fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this exists, it's not used in sink.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not a fan of this pattern of wrapping calls to deprecated code with no replacement with Deprecation::withSuppressedNotice(), rather than just using it to wrap Deprecation::notice() in a central place
I can see why you've done it this way as it means that developers who do happen to call any of these methods will actually see the deprecation notices if they turn on deprecations. However they're pretty unlikely to be very useful as they're telling the developer to use a method that doesn't actually exist.
Wrapping calls means that there is FAR more code updates that need to be made, and we may still end up missing a call or two. Just about every other CMS 5 PR could be closed if we didn't do it this way.
Looking at our own docs - https://docs.silverstripe.org/en/5/upgrading/deprecations/#enabling-deprecation-warnings - we do explicitly say that code with no replacement won't emit a deprecation notice by default, though there is a param available to turn on those notices too.
So if it's alright, could you please simply wrap the Deprecation::notice() with Deprecation::withSupressedNotice() and stop using wrapping the calls with withSupressedNotice()
Discussed offline - we're changing the way we do these a little bit. See #11428 This is blocked until that gets merged |
672f9e0
to
8a7c701
Compare
src/View/SSViewer.php
Outdated
*/ | ||
public static function getTemplateFileByType($identifier, $type = null) | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
src/View/SSViewer.php
Outdated
*/ | ||
public function exists() | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
src/View/SSViewer.php
Outdated
*/ | ||
public static function chooseTemplate($templates) | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
*/ | ||
public static function topLevel() | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
src/View/SSViewer.php
Outdated
*/ | ||
public function templates() | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
*/ | ||
public function findTemplate($template, $themes = null) | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
*/ | ||
public function castingClass($field) | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
*/ | ||
public function escapeTypeForField($field) | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
src/View/ViewableData.php
Outdated
*/ | ||
public function XML_val($field, $arguments = [], $cache = false) | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
src/View/ViewableData.php
Outdated
*/ | ||
public function getXMLValues($fields) | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it'); | |
Deprecation::noticeWithNoReplacment('5.4.0'); |
Dunno if I caught all the ones you listed - but as discussed in person I've done a very basic find and replace. If I missed any... well, it's the same message anyway so it's not worth updating them. |
8a7c701
to
39c5e02
Compare
Issue