From 9e3837a258ca661d0f8986eb7e07106b1b2f3971 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 8 Nov 2021 14:30:37 +0000 Subject: [PATCH] Issue #3158289 by alexpott, barboza: Deprecate hook_init for theme engines (cherry picked from commit 3ab612994270ac304afe47f8721acb28a666dfd4) --- core/lib/Drupal/Core/Theme/ThemeInitialization.php | 7 +++++++ .../tests/src/Functional/Theme/EngineNyanCatTest.php | 7 +++++++ core/themes/engines/twig/twig.engine | 10 ---------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/core/lib/Drupal/Core/Theme/ThemeInitialization.php b/core/lib/Drupal/Core/Theme/ThemeInitialization.php index 34b95e955c7..c81be077f54 100644 --- a/core/lib/Drupal/Core/Theme/ThemeInitialization.php +++ b/core/lib/Drupal/Core/Theme/ThemeInitialization.php @@ -140,11 +140,18 @@ class ThemeInitialization implements ThemeInitializationInterface { include_once $this->root . '/' . $active_theme->getOwner(); if (function_exists($theme_engine . '_init')) { + @trigger_error('THEME_ENGINE_init() is deprecated in drupal:9.3.0 and removed in drupal:10.0.0. There is no replacement. See https://www.drupal.org/node/3246978', E_USER_DEPRECATED); foreach ($active_theme->getBaseThemeExtensions() as $base) { call_user_func($theme_engine . '_init', $base); } call_user_func($theme_engine . '_init', $active_theme->getExtension()); } + else { + foreach ($active_theme->getBaseThemeExtensions() as $base) { + $base->load(); + } + $active_theme->getExtension()->load(); + } } else { // include non-engine theme files diff --git a/core/modules/system/tests/src/Functional/Theme/EngineNyanCatTest.php b/core/modules/system/tests/src/Functional/Theme/EngineNyanCatTest.php index 7a227da1ddb..0b8269a2cd3 100644 --- a/core/modules/system/tests/src/Functional/Theme/EngineNyanCatTest.php +++ b/core/modules/system/tests/src/Functional/Theme/EngineNyanCatTest.php @@ -30,8 +30,15 @@ class EngineNyanCatTest extends BrowserTestBase { /** * Ensures a theme's template is overridable based on the 'template' filename. + * + * @group legacy + * + * @todo https://www.drupal.org/project/drupal/issues/3246981 Remove + * nyan_cat_init() and the legacy group and expected deprecation from this + * test. */ public function testTemplateOverride() { + $this->expectDeprecation('THEME_ENGINE_init() is deprecated in drupal:9.3.0 and removed in drupal:10.0.0. There is no replacement. See https://www.drupal.org/node/3246978'); $this->config('system.theme') ->set('default', 'test_theme_nyan_cat_engine') ->save(); diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index 759fafcfb70..bcc984a02e2 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -26,16 +26,6 @@ function twig_extension() { return '.html.twig'; } -/** - * Includes .theme file from themes. - * - * @param \Drupal\Core\Extension\Extension $theme - * The theme extension object. - */ -function twig_init(Extension $theme) { - $theme->load(); -} - /** * Implements hook_render_template(). *