From bcdd1e2ca7ac27513fd5166f0efa65bdc856270e Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:42:40 +1300 Subject: [PATCH 1/4] API Remove deprecation notice from method we're not removing (#11540) We can't remove this method, because it will still be inherited from SingleSelectField. --- src/Forms/SearchableDropdownField.php | 12 ------------ src/Forms/SearchableDropdownTrait.php | 3 +-- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/Forms/SearchableDropdownField.php b/src/Forms/SearchableDropdownField.php index eb7c7d5beb6..0eb2a5aa642 100644 --- a/src/Forms/SearchableDropdownField.php +++ b/src/Forms/SearchableDropdownField.php @@ -26,16 +26,4 @@ public function __construct( $this->addExtraClass('ss-searchable-dropdown-field'); $this->setHasEmptyDefault(true); } - - /** - * @param string $string - * @return $this - * - * @deprecated 5.2.0 Use setPlaceholder() instead - */ - public function setEmptyString($string) - { - Deprecation::notice('5.2.0', 'Use setPlaceholder() instead'); - return parent::setEmptyString($string); - } } diff --git a/src/Forms/SearchableDropdownTrait.php b/src/Forms/SearchableDropdownTrait.php index 83a9a0bc13e..1b47589cbfc 100644 --- a/src/Forms/SearchableDropdownTrait.php +++ b/src/Forms/SearchableDropdownTrait.php @@ -159,8 +159,7 @@ public function getPlaceholder(): string * Calling this will also call setHasEmptyDefault(true), if the method exists on the class, * which is required for the placeholder functionality to work on SearchableDropdownField * - * In the case of SearchableDropField this method should be used instead of setEmptyString() which - * will be remvoved in a future version + * In the case of SearchableDropField this method should be used instead of setEmptyString() */ public function setPlaceholder(string $placeholder): static { From 10f239fe02480c340f7eaf57d8b104704a0b5be2 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 10 Jan 2025 14:02:24 +1300 Subject: [PATCH 2/4] FIX Don't throw error if there's no backtrace in deprecation notice --- src/Dev/Deprecation.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Dev/Deprecation.php b/src/Dev/Deprecation.php index 748ae45a0bd..c8cbcdf8d8e 100644 --- a/src/Dev/Deprecation.php +++ b/src/Dev/Deprecation.php @@ -157,6 +157,9 @@ public static function withSuppressedNotice(callable $func): mixed */ protected static function get_called_method_from_trace($backtrace, $level = 1) { + if ($backtrace === null) { + return ''; + } $level = (int)$level; if (!$level) { $level = 1; @@ -197,8 +200,11 @@ private static function get_called_from_trace(array $backtrace, int $level): arr return $called; } - private static function isCalledFromSupportedCode(array $backtrace): bool + private static function isCalledFromSupportedCode(?array $backtrace): bool { + if ($backtrace === null) { + return false; + } $called = Deprecation::get_called_from_trace($backtrace, 1); $file = $called['file'] ?? ''; if (!$file) { From 3f5b363688b027986a186227f983a0205a07fef3 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 10 Jan 2025 14:02:53 +1300 Subject: [PATCH 3/4] API Deprecate old i18n template syntax --- src/View/SSTemplateParser.peg | 4 +++- src/View/SSTemplateParser.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/View/SSTemplateParser.peg b/src/View/SSTemplateParser.peg index 098ce52b1eb..b9eac47aac0 100644 --- a/src/View/SSTemplateParser.peg +++ b/src/View/SSTemplateParser.peg @@ -896,7 +896,9 @@ class SSTemplateParser extends Parser implements TemplateParser */ function OldI18NTag_STR(&$res, $sub) { - $res['php'] = '$val .= ' . $sub['php'] . ';'; + $res['php'] = '$val .= ' . $sub['php'] . ';' . Deprecation::class + . '::notice(\'5.4.0\', \'The <% _t() %> template syntax is deprecated. Use <%t %> instead.\', ' + . Deprecation::class . '::SCOPE_GLOBAL);'; } /*!* diff --git a/src/View/SSTemplateParser.php b/src/View/SSTemplateParser.php index 3a586ba806a..9fc9f497d55 100644 --- a/src/View/SSTemplateParser.php +++ b/src/View/SSTemplateParser.php @@ -3748,7 +3748,9 @@ function match_OldI18NTag ($stack = array()) { function OldI18NTag_STR(&$res, $sub) { - $res['php'] = '$val .= ' . $sub['php'] . ';'; + $res['php'] = '$val .= ' . $sub['php'] . ';' . Deprecation::class + . '::notice(\'5.4.0\', \'The <% _t() %> template syntax is deprecated. Use <%t %> instead.\', ' + . Deprecation::class . '::SCOPE_GLOBAL);'; } /* NamedArgument: Name:Word "=" Value:Argument */ From 94af2e58d29efa8a7fed94175c40a8efa09e584d Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 10 Jan 2025 14:03:05 +1300 Subject: [PATCH 4/4] FIX Stop calling deprecated method in templates --- src/View/SSTemplateParser.peg | 4 +++- src/View/SSTemplateParser.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/View/SSTemplateParser.peg b/src/View/SSTemplateParser.peg index b9eac47aac0..5836d866e03 100644 --- a/src/View/SSTemplateParser.peg +++ b/src/View/SSTemplateParser.peg @@ -1155,7 +1155,9 @@ class SSTemplateParser extends Parser implements TemplateParser if ($res['ArgumentCount'] != 0) { throw new SSTemplateParseException('Base_tag takes no arguments', $this); } - return '$val .= \\SilverStripe\\View\\SSViewer::get_base_tag($val);'; + $code = '$isXhtml = preg_match(\'/]+xhtml/i\', $val);'; + $code .= PHP_EOL . '$val .= \\SilverStripe\\View\\SSViewer::getBaseTag($isXhtml);'; + return $code; } /** diff --git a/src/View/SSTemplateParser.php b/src/View/SSTemplateParser.php index 9fc9f497d55..a34dd9c73f7 100644 --- a/src/View/SSTemplateParser.php +++ b/src/View/SSTemplateParser.php @@ -4440,7 +4440,9 @@ function OpenBlock_Handle_Base_tag(&$res) if ($res['ArgumentCount'] != 0) { throw new SSTemplateParseException('Base_tag takes no arguments', $this); } - return '$val .= \\SilverStripe\\View\\SSViewer::get_base_tag($val);'; + $code = '$isXhtml = preg_match(\'/]+xhtml/i\', $val);'; + $code .= PHP_EOL . '$val .= \\SilverStripe\\View\\SSViewer::getBaseTag($isXhtml);'; + return $code; } /**