-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,15 @@ | |
|
||
use InvalidArgumentException; | ||
use SilverStripe\Core\ClassInfo; | ||
use SilverStripe\Dev\Deprecation; | ||
use SilverStripe\ORM\FieldType\DBField; | ||
|
||
/** | ||
* This extends SSViewer_Scope to mix in data on top of what the item provides. This can be "global" | ||
* data that is scope-independant (like BaseURL), or type-specific data that is layered on top cross-cut like | ||
* (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 | ||
Comment on lines
-14
to
17
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. |
||
{ | ||
|
@@ -65,6 +66,7 @@ public function __construct( | |
array $underlay = null, | ||
SSViewer_Scope $inheritedScope = null | ||
) { | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be merged into ' . SSViewer_Scope::class, Deprecation::SCOPE_CLASS); | ||
parent::__construct($item, $inheritedScope); | ||
|
||
$this->overlay = $overlay ?: []; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
namespace SilverStripe\View; | ||
|
||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\Dev\Deprecation; | ||
|
||
/** | ||
* 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 commentThe 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. |
||
{ | ||
|
@@ -37,6 +39,11 @@ class SSViewer_FromString extends SSViewer | |
*/ | ||
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) { | ||
$this->setParser($parser); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use ArrayIterator; | ||
use Countable; | ||
use Iterator; | ||
use SilverStripe\Dev\Deprecation; | ||
use SilverStripe\ORM\FieldType\DBBoolean; | ||
use SilverStripe\ORM\FieldType\DBText; | ||
use SilverStripe\ORM\FieldType\DBFloat; | ||
|
@@ -123,16 +124,23 @@ public function __construct($item, SSViewer_Scope $inheritedScope = null) | |
* Returns the current "active" item | ||
* | ||
* @return object | ||
* @deprecated 5.4.0 use getCurrentItem() instead. | ||
*/ | ||
public function getItem() | ||
{ | ||
Deprecation::notice('5.4.0', 'use getCurrentItem() instead.'); | ||
Comment on lines
+127
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = $this->itemIterator ? $this->itemIterator->current() : $this->item; | ||
if (is_scalar($item)) { | ||
$item = $this->convertScalarToDBField($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 | ||
* | ||
|
@@ -185,7 +193,7 @@ public function resetLocalScope() | |
*/ | ||
public function getObj($name, $arguments = [], $cache = false, $cacheName = null) | ||
{ | ||
$on = $this->getItem(); | ||
$on = $this->getCurrentItem(); | ||
if ($on === null) { | ||
return null; | ||
} | ||
|
@@ -198,9 +206,11 @@ public function getObj($name, $arguments = [], $cache = false, $cacheName = null | |
* @param bool $cache | ||
* @param string $cacheName | ||
* @return $this | ||
* @deprecated 5.4.0 Will be renamed scopeToIntermediateValue() | ||
*/ | ||
public function obj($name, $arguments = [], $cache = false, $cacheName = null) | ||
Comment on lines
+209
to
211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is getting renamed so it's clear what it's for |
||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed scopeToIntermediateValue()'); | ||
switch ($name) { | ||
case 'Up': | ||
if ($this->upIndex === null) { | ||
|
@@ -252,7 +262,7 @@ public function obj($name, $arguments = [], $cache = false, $cacheName = null) | |
*/ | ||
public function self() | ||
{ | ||
$result = $this->getItem(); | ||
$result = $this->getCurrentItem(); | ||
$this->resetLocalScope(); | ||
|
||
return $result; | ||
|
@@ -350,8 +360,12 @@ public function next() | |
*/ | ||
public function __call($name, $arguments) | ||
{ | ||
$on = $this->getItem(); | ||
$retval = $on ? $on->$name(...$arguments) : null; | ||
$on = $this->getCurrentItem(); | ||
if ($on instanceof ViewableData && $name === 'XML_val') { | ||
$retval = $on->XML_val(...$arguments); | ||
} else { | ||
$retval = $on ? $on->$name(...$arguments) : null; | ||
} | ||
|
||
$this->resetLocalScope(); | ||
return $retval; | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,6 +9,7 @@ | |||||
use SilverStripe\Core\Manifest\ModuleLoader; | ||||||
use SilverStripe\Core\Manifest\ModuleResourceLoader; | ||||||
use SilverStripe\Core\Path; | ||||||
use SilverStripe\Dev\Deprecation; | ||||||
|
||||||
/** | ||||||
* Handles finding templates from a stack of template manifest objects. | ||||||
|
@@ -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 commentThe 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 |
||||||
{ | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if ($themes === null) { | ||||||
$themes = SSViewer::get_themes(); | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe 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 |
||||||
{ | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Strip arguments | ||||||
$spec = $this->castingHelper($field); | ||||||
return trim(strtok($spec ?? '', '(') ?? ''); | ||||||
|
@@ -439,9 +441,11 @@ 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 commentThe 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 |
||||||
{ | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$class = $this->castingClass($field) ?: $this->config()->get('default_cast'); | ||||||
|
||||||
/** @var DBField $type */ | ||||||
|
@@ -488,9 +492,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 commentThe reason will be displayed to describe this comment to others. Learn more. You'll see in the implementations for |
||||||
{ | ||||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be made private'); | ||||||
return $arguments | ||||||
? $fieldName . ":" . var_export($arguments, true) | ||||||
: $fieldName; | ||||||
|
@@ -546,6 +552,9 @@ protected function objCacheClear() | |||||
*/ | ||||||
public function obj($fieldName, $arguments = [], $cache = false, $cacheName = null) | ||||||
{ | ||||||
if ($cacheName !== null) { | ||||||
Deprecation::noticeWithNoReplacment('5.4.0', 'The $cacheName parameter has been deprecated and will be removed'); | ||||||
} | ||||||
if (!$cacheName && $cache) { | ||||||
$cacheName = $this->objCacheName($fieldName, $arguments); | ||||||
} | ||||||
|
@@ -588,9 +597,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 commentThe reason will be displayed to describe this comment to others. Learn more. Nothing uses this, and if they did they should just call |
||||||
{ | ||||||
Deprecation::notice('5.4.0', 'Use obj() instead'); | ||||||
return $this->obj($fieldName, $arguments, true, $identifier); | ||||||
} | ||||||
|
||||||
|
@@ -617,9 +628,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 commentThe reason will be displayed to describe this comment to others. Learn more. This is currently called directly from |
||||||
{ | ||||||
Deprecation::noticeWithNoReplacment('5.4.0'); | ||||||
$result = $this->obj($field, $arguments, $cache); | ||||||
// Might contain additional formatting over ->XML(). E.g. parse shortcodes, nl2br() | ||||||
return $result->forTemplate(); | ||||||
|
@@ -630,9 +643,11 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this exists, it's not used in sink. |
||||||
{ | ||||||
Deprecation::noticeWithNoReplacment('5.4.0'); | ||||||
$result = []; | ||||||
|
||||||
foreach ($fields as $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.
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 toGridField::getDataFieldValue()
.Found this because it's the only usage of
XML_val()
in core.