From 0e8a558b4f451972b906a13bd3c84f0f21d70ead Mon Sep 17 00:00:00 2001 From: Lauri Eskola Date: Tue, 28 Mar 2023 10:43:07 +0300 Subject: [PATCH] Issue #3348848 by andypost, Purencool, daffie: Deprecate theme_get_registry() --- core/includes/theme.inc | 7 +++++++ core/lib/Drupal/Core/Render/theme.api.php | 2 +- .../Drupal/KernelTests/Core/Theme/RegistryTest.php | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 8629f44f79e1..0becb4ef6863 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -87,13 +87,20 @@ const RESPONSIVE_PRIORITY_LOW = 'priority-low'; * @return array|\Drupal\Core\Utility\ThemeRegistry * The complete theme registry array, or an instance of the * Drupal\Core\Utility\ThemeRegistry class. + * + * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use + * theme.registry service methods get() or getRuntime() instead. + * + * @see https://www.drupal.org/node/3348850 */ function theme_get_registry($complete = TRUE) { $theme_registry = \Drupal::service('theme.registry'); if ($complete) { + @trigger_error(__FUNCTION__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use theme.registry service method get() instead. See https://www.drupal.org/node/3348850', E_USER_DEPRECATED); return $theme_registry->get(); } else { + @trigger_error(__FUNCTION__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use theme.registry service method getRuntime() instead. See https://www.drupal.org/node/3348850', E_USER_DEPRECATED); return $theme_registry->getRuntime(); } } diff --git a/core/lib/Drupal/Core/Render/theme.api.php b/core/lib/Drupal/Core/Render/theme.api.php index 8e77a9c95e7e..cb960152278a 100644 --- a/core/lib/Drupal/Core/Render/theme.api.php +++ b/core/lib/Drupal/Core/Render/theme.api.php @@ -547,7 +547,7 @@ function hook_preprocess(&$variables, $hook) { } if (!isset($hooks)) { - $hooks = theme_get_registry(); + $hooks = \Drupal::service('theme.registry')->get(); } // Determine the primary theme function argument. diff --git a/core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php b/core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php index 761c785384a3..c4669370b2b7 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php @@ -272,4 +272,18 @@ class RegistryTest extends KernelTestBase { $this->assertSame($hooks, $registry->get()); } + /** + * Tests deprecated theme_get_registry function. + * + * @see theme_get_registry() + * @group legacy + */ + public function testLegacyThemeGetRegistry() { + $registry = \Drupal::service('theme.registry'); + $this->expectDeprecation('theme_get_registry() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use theme.registry service method get() instead. See https://www.drupal.org/node/3348850'); + $this->assertEquals($registry->get(), theme_get_registry()); + $this->expectDeprecation('theme_get_registry() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use theme.registry service method getRuntime() instead. See https://www.drupal.org/node/3348850'); + $this->assertEquals($registry->getRuntime(), theme_get_registry(FALSE)); + } + }