Skip to content

Commit

Permalink
API Deprecations for template layer
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Oct 10, 2024
1 parent 483e944 commit 044d44b
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 105 deletions.
6 changes: 4 additions & 2 deletions src/Control/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Core\ClassInfo;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
Expand Down Expand Up @@ -455,7 +456,8 @@ protected function definingClassForAction($action)
$class = static::class;
while ($class != 'SilverStripe\\Control\\RequestHandler') {
$templateName = strtok($class ?? '', '_') . '_' . $action;
if (SSViewer::hasTemplate($templateName)) {
$templateExists = Deprecation::withSuppressedNotice(fn() => SSViewer::hasTemplate($templateName));
if ($templateExists) {
return $class;
}

Expand Down Expand Up @@ -487,7 +489,7 @@ public function hasActionTemplate($action)
$parentClass = get_parent_class($parentClass ?? '');
}

return SSViewer::hasTemplate($templates);
return Deprecation::withSuppressedNotice(fn() => SSViewer::hasTemplate($templates));
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Control/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
Expand Down Expand Up @@ -402,9 +403,11 @@ public function getHTMLTemplate(): string
return $this->HTMLTemplate;
}

return ThemeResourceLoader::inst()->findTemplate(
SSViewer::get_templates_by_class(static::class, '', Email::class),
SSViewer::get_themes()
return Deprecation::withSuppressedNotice(
fn() => ThemeResourceLoader::inst()->findTemplate(
SSViewer::get_templates_by_class(static::class, '', Email::class),
SSViewer::get_themes()
)
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Forms/GridField/GridFieldAddExistingAutocompleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use SilverStripe\View\SSViewer;
use LogicException;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Dev\Deprecation;

/**
* This class is is responsible for adding objects to another object's has_many
Expand Down Expand Up @@ -283,7 +284,7 @@ public function doSearch($gridField, $request)
$json = [];
Config::nest();
SSViewer::config()->set('source_file_comments', false);
$viewer = SSViewer::fromString($this->resultsFormat);
$viewer = Deprecation::withSuppressedNotice(fn() => SSViewer::fromString($this->resultsFormat));
foreach ($results as $result) {
if (!$result->canView()) {
continue;
Expand Down
5 changes: 4 additions & 1 deletion src/Forms/GridField/GridFieldDataColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Core\Convert;
use InvalidArgumentException;
use LogicException;
use SilverStripe\Dev\Deprecation;
use SilverStripe\View\ViewableData;

/**
Expand Down Expand Up @@ -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)
{
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++) {
$methodName = $fieldNameParts[$idx];
// Last mmethod call from $columnName return what that method is returning
if ($idx == sizeof($fieldNameParts ?? []) - 1) {
return $tmpItem->XML_val($methodName);
return Deprecation::withSuppressedNotice(fn() => $tmpItem->XML_val($methodName));
}
// else get the object from this $methodName
$tmpItem = $tmpItem->$methodName();
Expand Down
5 changes: 4 additions & 1 deletion src/Forms/HTMLEditor/HTMLEditorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use Exception;
use SilverStripe\Dev\Deprecation;
use SilverStripe\View\Parsers\HTMLValue;

/**
Expand Down Expand Up @@ -129,7 +130,9 @@ public function getAttributes()
*/
public function saveInto(DataObjectInterface $record)
{
if ($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
if ($record->hasField($this->name)
&& Deprecation::withSuppressedNotice(fn () => $record->escapeTypeForField($this->name)) != 'xml'
) {
throw new Exception(
'HTMLEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.'
);
Expand Down
2 changes: 1 addition & 1 deletion src/View/SSTemplateParser.peg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/View/SSTemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3897,7 +3897,7 @@ function Include__finalise(&$res)
$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
Expand Down
Loading

0 comments on commit 044d44b

Please sign in to comment.