diff --git a/core/includes/theme.inc b/core/includes/theme.inc index a0a2b0f..069b497 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -10,13 +10,11 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Url; -use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\Config; use Drupal\Core\Language\Language; use Drupal\Core\Extension\ExtensionNameLengthException; use Drupal\Core\Template\Attribute; use Drupal\Core\Template\RenderWrapper; -use Drupal\Core\Utility\ThemeRegistry; use Drupal\Core\Theme\ThemeSettings; use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\MapArray; diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php index 0a82082..3c5ada7 100644 --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -293,14 +293,6 @@ public function getBaseHook($hook) { * @see theme() * @see hook_theme_registry_alter() * - * @param string $theme - * The loaded $theme object as returned by list_themes(). - * @param array $base_theme - * An array of loaded $theme objects representing the ancestor themes in - * oldest first order. - * @param string $theme_engine - * The name of the theme engine. - * * @return \Drupal\Core\Utility\ThemeRegistry * The build theme registry. */ @@ -388,10 +380,10 @@ protected function build() { * @param string $type * One of 'module', 'theme_engine', 'base_theme_engine', 'theme', or * 'base_theme'. Unlike regular hooks that can only be implemented by - * modules, each of these can implement hook_theme(). - * _theme_process_registry() is called in aforementioned order and new - * entries override older ones. For example, if a theme hook is both defined - * by a module and a theme, then the definition in the theme will be used. + * modules, each of these can implement hook_theme(). This function is + * called in aforementioned order and new entries override older ones. For + * example, if a theme hook is both defined by a module and a theme, then + * the definition in the theme will be used. * @param \stdClass $theme * The loaded $theme object as returned from list_themes(). * @param string $path @@ -574,6 +566,9 @@ public function destruct() { /** * Wraps drupal_get_path(). * + * @param string $module + * The name of the item for which the path is requested. + * * @return string */ protected function getPath($module) { @@ -593,7 +588,7 @@ protected function listThemes() { * Wraps drupal_theme_initialize(). */ protected function initializeTheme() { - return drupal_theme_initialize(); + drupal_theme_initialize(); } } diff --git a/core/lib/Drupal/Core/Utility/ThemeRegistry.php b/core/lib/Drupal/Core/Utility/ThemeRegistry.php index e09ed65..0979e07 100644 --- a/core/lib/Drupal/Core/Utility/ThemeRegistry.php +++ b/core/lib/Drupal/Core/Utility/ThemeRegistry.php @@ -63,7 +63,6 @@ function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $l if ($this->persistable && $cached = $this->cache->get($this->cid)) { $this->storage = $cached->data; - $data = $cached->data; } else { // If there is no runtime cache stored, fetch the full theme registry, diff --git a/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php b/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php index 41129cc..2e5417d 100644 --- a/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php +++ b/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php @@ -7,9 +7,7 @@ namespace Drupal\theme_test\EventSubscriber; -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerAware; -use Symfony\Component\DependencyInjection\IntrospectableContainerInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index dd548bf..7af12f7 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Language\Language; +use Drupal\Core\Theme\Registry; use Drupal\views\Plugin\views\area\AreaPluginBase; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\PluginBase; @@ -1756,54 +1757,21 @@ public function buildOptionsForm(&$form, &$form_state) { } if (isset($GLOBALS['theme']) && $GLOBALS['theme'] == $this->theme) { - $this->theme_registry = theme_get_registry(); + $this->theme_registry = \Drupal::service('theme.registry')->get(); $theme_engine = $GLOBALS['theme_engine']; } else { $themes = list_themes(); $theme = $themes[$this->theme]; - // Find all our ancestor themes and put them in an array. - $base_theme = array(); - $ancestor = $this->theme; - while ($ancestor && isset($themes[$ancestor]->base_theme)) { - $ancestor = $themes[$ancestor]->base_theme; - $base_theme[] = $themes[$ancestor]; - } - - // The base themes should be initialized in the right order. - $base_theme = array_reverse($base_theme); - - // This code is copied directly from _drupal_theme_initialize() + // @see _drupal_theme_initialize() $theme_engine = NULL; - // Initialize the theme. if (isset($theme->engine)) { - // Include the engine. - include_once DRUPAL_ROOT . '/' . $theme->owner; - $theme_engine = $theme->engine; - if (function_exists($theme_engine . '_init')) { - foreach ($base_theme as $base) { - call_user_func($theme_engine . '_init', $base); - } - call_user_func($theme_engine . '_init', $theme); - } } - else { - // include non-engine theme files - foreach ($base_theme as $base) { - // Include the theme file or the engine. - if (!empty($base->owner)) { - include_once DRUPAL_ROOT . '/' . $base->owner; - } - } - // and our theme gets one too. - if (!empty($theme->owner)) { - include_once DRUPAL_ROOT . '/' . $theme->owner; - } - } - $this->theme_registry = _theme_load_registry($theme, $base_theme, $theme_engine); + $cache_theme = \Drupal::service('cache.theme'); + $this->theme_registry = new Registry($cache_theme, \Drupal::lock(), \Drupal::moduleHandler(), $theme->name); } // If there's a theme engine involved, we also need to know its extension @@ -2071,15 +2039,9 @@ public function buildOptionsForm(&$form, &$form_state) { * a templates rescan). */ public function rescanThemes($form, &$form_state) { - drupal_theme_rebuild(); - - // The 'Theme: Information' page is about to be shown again. That page - // analyzes the output of theme_get_registry(). However, this latter - // function uses an internal cache (which was initialized before we - // called drupal_theme_rebuild()) so it won't reflect the - // current state of our theme registry. The only way to clear that cache - // is to re-initialize the theme system: - unset($GLOBALS['theme']); + // Analyzes the data of the theme registry. + \Drupal::service('theme.registry')->reset(); + drupal_theme_initialize(); $form_state['rerender'] = TRUE; diff --git a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php index 2ec8003..399f223 100644 --- a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php @@ -23,7 +23,7 @@ class RegistryTest extends UnitTestCase { /** * The tested theme registry. * - * @var \Drupal\Core\Theme\Registry + * @var \Drupal\Tests\Core\Theme\TestRegistry */ protected $registry;