diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 8629f44f79e157f2f3891def04b1196e83665b02..0becb4ef6863de120341b327691825d0378142aa 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -87,13 +87,20 @@ * @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 8e77a9c95e7e6423766e052b71e8e7f8425a009e..cb960152278ad64531f71edfef6925ddf8bc5db5 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 761c785384a32c8c32ab705d66a4b4f7b43558aa..c4669370b2b7e49a2f524e59b363e723980b3dbd 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php @@ -272,4 +272,18 @@ public function testLegacyThemeRegistryRebuild() { $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)); + } + }