--- 1981.diff 2023-01-17 16:24:39.772931594 -0300 +++ 3270148-18.patch 2023-01-17 19:54:44.402836157 -0300 @@ -1,17 +1,103 @@ +diff --git a/core/assets/scaffold/files/default.services.yml b/core/assets/scaffold/files/default.services.yml +index b4d27e05a5..aafb949fa5 100644 +--- a/core/assets/scaffold/files/default.services.yml ++++ b/core/assets/scaffold/files/default.services.yml +@@ -108,6 +108,15 @@ parameters: + - js + - svg + - twig ++ # Twig deprecations: ++ # ++ # By default, twig deprecations will trigger a deprecated message when a variable is deprecated. ++ # ++ # For more information about deprecations, see ++ # https://www.drupal.org/node/3270148 ++ # ++ # @default true ++ deprecations: true + renderer.config: + # Renderer required cache contexts: + # +diff --git a/core/core.services.yml b/core/core.services.yml +index 6655001af1..83339f2023 100644 +--- a/core/core.services.yml ++++ b/core/core.services.yml +@@ -21,6 +21,7 @@ parameters: + - js + - svg + - twig ++ deprecations: true + renderer.config: + required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions'] + auto_placeholder_conditions: +@@ -1710,7 +1711,7 @@ services: + Drupal\Core\Template\TwigEnvironment: '@twig' + twig.extension: + class: Drupal\Core\Template\TwigExtension +- arguments: ['@renderer', '@url_generator', '@theme.manager', '@date.formatter', '@file_url_generator'] ++ arguments: ['@renderer', '@url_generator', '@theme.manager', '@date.formatter', '@file_url_generator', '%twig.config%'] + tags: + - { name: twig.extension, priority: 100 } + twig.extension.debug: diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php -index 1a75a9a6ac92dcc9d11572ebd1c51f1bd4e03a1f..9169a460386719df2b3cc6f6fcc70457648f0f00 100644 +index 0e99830fc5..9787343335 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php -@@ -158,6 +158,7 @@ public function getNodeVisitors() { +@@ -69,6 +69,13 @@ class TwigExtension extends AbstractExtension { + */ + protected $fileUrlGenerator; + ++ /** ++ * Twig deprecations. ++ * ++ * @var bool ++ */ ++ protected $deprecations = TRUE; ++ + /** + * Constructs \Drupal\Core\Template\TwigExtension. + * +@@ -82,13 +89,19 @@ class TwigExtension extends AbstractExtension { + * The date formatter. + * @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator + * The file URL generator. ++ * @param mixed[] $twig_config ++ * Twig configuration from the service container. + */ +- public function __construct(RendererInterface $renderer, UrlGeneratorInterface $url_generator, ThemeManagerInterface $theme_manager, DateFormatterInterface $date_formatter, FileUrlGeneratorInterface $file_url_generator) { ++ public function __construct(RendererInterface $renderer, UrlGeneratorInterface $url_generator, ThemeManagerInterface $theme_manager, DateFormatterInterface $date_formatter, FileUrlGeneratorInterface $file_url_generator, array $twig_config = []) { + $this->renderer = $renderer; + $this->urlGenerator = $url_generator; + $this->themeManager = $theme_manager; + $this->dateFormatter = $date_formatter; + $this->fileUrlGenerator = $file_url_generator; ++ ++ if (isset($twig_config['deprecations'])) { ++ $this->deprecations = $twig_config['deprecations']; ++ } + } + + /** +@@ -154,9 +167,16 @@ public function getFilters() { + public function getNodeVisitors() { + // The node visitor is needed to wrap all variables with // render_var -> TwigExtension->renderVar() function. - return [ +- return [ ++ $node_visitors = [ new TwigNodeVisitor(), -+ new TwigNodeVisitorCheckDeprecations(), ]; ++ ++ // Add the deprecations check if the setting is configured. ++ if ($this->deprecations) { ++ $node_visitors[] = new TwigNodeVisitorCheckDeprecations(); ++ } ++ ++ return $node_visitors; } -@@ -657,4 +658,22 @@ public function withoutFilter($element) { - return $filtered_element; + /** +@@ -712,4 +732,22 @@ public function suggestThemeHook(?array $element, string|\Stringable $suggestion + return $element; } + /** @@ -35,7 +121,7 @@ } diff --git a/core/lib/Drupal/Core/Template/TwigNodeCheckDeprecations.php b/core/lib/Drupal/Core/Template/TwigNodeCheckDeprecations.php new file mode 100644 -index 0000000000000000000000000000000000000000..618dfc93c6c7072756aaf55e5aed5ecd4c906a26 +index 0000000000..618dfc93c6 --- /dev/null +++ b/core/lib/Drupal/Core/Template/TwigNodeCheckDeprecations.php @@ -0,0 +1,50 @@ @@ -91,10 +177,10 @@ +} diff --git a/core/lib/Drupal/Core/Template/TwigNodeVisitorCheckDeprecations.php b/core/lib/Drupal/Core/Template/TwigNodeVisitorCheckDeprecations.php new file mode 100644 -index 0000000000000000000000000000000000000000..85cd6f89f4f6af8cb403df86fdec047142801b0f +index 0000000000..d0d1979bc5 --- /dev/null +++ b/core/lib/Drupal/Core/Template/TwigNodeVisitorCheckDeprecations.php -@@ -0,0 +1,60 @@ +@@ -0,0 +1,63 @@ +assertEquals($template_after, $output); +@@ -288,4 +289,24 @@ public function testTwigFilePrefixChange() { + $this->assertEquals(count(array_unique($cache_filenames)), 1); } + /** @@ -197,11 +273,31 @@ + 'foo' => 'foo', + 'bar' => 'bar', + 'deprecations' => ['foo' => 'foo is deprecated'], -+ ], ++ ], + ]; -+ $this->addExpectedDeprecationMessage('foo is deprecated'); ++ $this->expectDeprecation('foo is deprecated'); + $rendered = $renderer->renderRoot($element); -+ $this->assertEqual($rendered, 'foobar'); ++ $this->assertEquals('foobar', $rendered); + } + } +diff --git a/sites/default/default.services.yml b/sites/default/default.services.yml +index b4d27e05a5..aafb949fa5 100644 +--- a/sites/default/default.services.yml ++++ b/sites/default/default.services.yml +@@ -108,6 +108,15 @@ parameters: + - js + - svg + - twig ++ # Twig deprecations: ++ # ++ # By default, twig deprecations will trigger a deprecated message when a variable is deprecated. ++ # ++ # For more information about deprecations, see ++ # https://www.drupal.org/node/3270148 ++ # ++ # @default true ++ deprecations: true + renderer.config: + # Renderer required cache contexts: + #