diff --git a/core/includes/theme.inc b/core/includes/theme.inc index dd8e9be..1399862 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -580,14 +580,14 @@ function theme($hook, $variables = array()) { throw new Exception(t('theme() may not be called until all modules are loaded.')); } - /** @var \Drupal\Core\Utility\ThemeRegistry $hooks */ - $hooks = \Drupal::service('theme.registry')->getRuntime(); + /** @var \Drupal\Core\Utility\ThemeRegistry $theme_registry */ + $theme_registry = \Drupal::service('theme.registry')->getRuntime(); // If an array of hook candidates were passed, use the first one that has an // implementation. if (is_array($hook)) { foreach ($hook as $candidate) { - if ($hooks->has($candidate)) { + if ($theme_registry->has($candidate)) { break; } } @@ -599,16 +599,16 @@ function theme($hook, $variables = array()) { // If there's no implementation, check for more generic fallbacks. If there's // still no implementation, log an error and return an empty string. - if (!$hooks->has($hook)) { + if (!$theme_registry->has($hook)) { // Iteratively strip everything after the last '__' delimiter, until an // implementation is found. while ($pos = strrpos($hook, '__')) { $hook = substr($hook, 0, $pos); - if ($hooks->has($hook)) { + if ($theme_registry->has($hook)) { break; } } - if (!$hooks->has($hook)) { + if (!$theme_registry->has($hook)) { // Only log a message when not trying theme suggestions ($hook being an // array). if (!isset($candidate)) { @@ -621,7 +621,7 @@ function theme($hook, $variables = array()) { } } - $info = $hooks->get($hook); + $info = $theme_registry->get($hook); global $theme_path; $temp = $theme_path; // point path_to_theme() to the currently used theme path: @@ -694,8 +694,8 @@ function theme($hook, $variables = array()) { // 'node__article' as a suggestion via hook_theme_suggestions_HOOK_alter(), // enabling a theme to have an alternate template file for article nodes. foreach (array_reverse($suggestions) as $suggestion) { - if ($hooks->has($suggestion)) { - $info = $hooks->get($suggestion); + if ($theme_registry->has($suggestion)) { + $info = $theme_registry->get($suggestion); break; } } @@ -703,7 +703,7 @@ function theme($hook, $variables = array()) { // Invoke the variable preprocessors, if any. if (isset($info['base hook'])) { $base_hook = $info['base hook']; - $base_hook_info = $hooks->get($base_hook); + $base_hook_info = $theme_registry->get($base_hook); // Include files required by the base hook, since its variable preprocessors // might reside there. if (!empty($base_hook_info['includes'])) { diff --git a/core/includes/update.inc b/core/includes/update.inc index c616e08..7b8a6e2 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -459,7 +459,8 @@ function update_prepare_d8_bootstrap() { $kernel = new DrupalKernel('update', drupal_classloader(), FALSE); $kernel->boot(); - // Remove the theme_registry cache entry from D7. + // Clear the D7 caches, to ensure that for example the theme_registry does not + // take part in the upgrade process. Drupal::cache('cache')->deleteAll(); } diff --git a/core/lib/Drupal/Core/Path/AliasWhitelist.php b/core/lib/Drupal/Core/Path/AliasWhitelist.php index d43f83e..9e3a6a1 100644 --- a/core/lib/Drupal/Core/Path/AliasWhitelist.php +++ b/core/lib/Drupal/Core/Path/AliasWhitelist.php @@ -88,20 +88,20 @@ protected function loadMenuPathRoots() { /** * {@inheritdoc} */ - public function get($key) { + public function get($offset) { $this->lazyLoadCache(); // url() may be called with paths that are not represented by menu router // items such as paths that will be rewritten by hook_url_outbound_alter(). // Therefore internally TRUE is used to indicate whitelisted paths. FALSE is // used to indicate paths that have already been checked but are not // whitelisted, and NULL indicates paths that have not been checked yet. - if (isset($this->storage[$key])) { - if ($this->storage[$key]) { + if (isset($this->storage[$offset])) { + if ($this->storage[$offset]) { return TRUE; } } - elseif (array_key_exists($key, $this->storage)) { - return $this->resolveCacheMiss($key); + elseif (array_key_exists($offset, $this->storage)) { + return $this->resolveCacheMiss($offset); } } diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php index 3893338..0a82082 100644 --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -210,7 +210,7 @@ public function get() { $this->registry = $cache->data; } else { - $this->registry = $this->build($this->theme, $this->baseThemes, $this->engine); + $this->registry = $this->build(); // Only persist it if all modules are loaded to ensure it is complete. if ($this->moduleHandler->isLoaded()) { $this->setCache(); @@ -304,7 +304,7 @@ public function getBaseHook($hook) { * @return \Drupal\Core\Utility\ThemeRegistry * The build theme registry. */ - protected function build($theme, array $base_theme, $theme_engine) { + protected function build() { $cache = array(); // First, preprocess the theme hooks advertised by modules. This will // serve as the basic registry. Since the list of enabled modules is the @@ -324,22 +324,22 @@ protected function build($theme, array $base_theme, $theme_engine) { } // Process each base theme. - foreach ($base_theme as $base) { + foreach ($this->baseThemes as $base) { // If the base theme uses a theme engine, process its hooks. $base_path = dirname($base->filename); - if ($theme_engine) { - $this->processExtension($cache, $theme_engine, 'base_theme_engine', $base->name, $base_path); + if ($this->engine) { + $this->processExtension($cache, $this->engine, 'base_theme_engine', $base->name, $base_path); } $this->processExtension($cache, $base->name, 'base_theme', $base->name, $base_path); } // And then the same thing, but for the theme. - if ($theme_engine) { - $this->processExtension($cache, $theme_engine, 'theme_engine', $theme->name, dirname($theme->filename)); + if ($this->engine) { + $this->processExtension($cache, $this->engine, 'theme_engine', $this->theme->name, dirname($this->theme->filename)); } // Finally, hooks provided by the theme itself. - $this->processExtension($cache, $theme->name, 'theme', $theme->name, dirname($theme->filename)); + $this->processExtension($cache, $this->theme->name, 'theme', $this->theme->name, dirname($this->theme->filename)); // Let modules alter the registry. $this->moduleHandler->alter('theme_registry', $cache); diff --git a/core/modules/locale/lib/Drupal/locale/LocaleLookup.php b/core/modules/locale/lib/Drupal/locale/LocaleLookup.php index 54b3495..2003e4e 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleLookup.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleLookup.php @@ -82,10 +82,10 @@ public function __construct($langcode, $context, StringStorageInterface $string_ /** * {@inheritdoc} */ - protected function resolveCacheMiss($key) { + protected function resolveCacheMiss($offset) { $translation = $this->stringStorage->findTranslation(array( 'language' => $this->langcode, - 'source' => $key, + 'source' => $offset, 'context' => $this->context, )); @@ -96,19 +96,19 @@ protected function resolveCacheMiss($key) { // We don't have the source string, update the {locales_source} table to // indicate the string is not translated. $this->stringStorage->createString(array( - 'source' => $key, + 'source' => $offset, 'context' => $this->context, 'version' => \Drupal::VERSION ))->addLocation('path', request_uri())->save(); $value = TRUE; } - $this->storage[$key] = $value; + $this->storage[$offset] = $value; // Disabling the usage of string caching allows a module to watch for // the exact list of strings used on a page. From a performance // perspective that is a really bad idea, so we have no user // interface for this. Be careful when turning this option off! if (\Drupal::config('locale.settings')->get('cache_strings')) { - $this->persist($key); + $this->persist($offset); } return $value; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php index b6c76c8..5689b3d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php @@ -82,9 +82,9 @@ function testTwigCacheOverride() { ->set('default', 'test_theme') ->save(); - // Unset the global variables, so \Drupal\Core\Theme::init() fires - // drupal_theme_initialize, which fills up the global variables properly and - // choosed the current active theme. + // Unset the global variables, so \Drupal\Core\Theme\Registry::init() fires + // drupal_theme_initialize, which fills up the global variables properly + // and chosen the current active theme. unset($GLOBALS['theme_info']); unset($GLOBALS['theme']); // Reset the theme registry, so that the new theme is used. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index ad29ada..3e0104b 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1348,7 +1348,7 @@ function hook_theme($existing, $type, $theme, $path) { * * The $theme_registry array is keyed by theme hook name, and contains the * information returned from hook_theme(), as well as additional properties - * added by \Drupal\Core\Theme\Registry::_theme_process_registry(). + * added by \Drupal\Core\Theme\Registry::processExtension(). * * For example: * @code diff --git a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php index 8445150..2ec8003 100644 --- a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php @@ -35,7 +35,7 @@ class RegistryTest extends UnitTestCase { protected $cache; /** - * The mocked lock backend.. + * The mocked lock backend. * * @var \Drupal\Core\Lock\LockBackendInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -48,6 +48,9 @@ class RegistryTest extends UnitTestCase { */ protected $moduleHandler; + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Theme Registry', @@ -56,6 +59,9 @@ public static function getInfo() { ); } + /** + * {@inheritdoc} + */ protected function setUp() { $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); @@ -64,6 +70,9 @@ protected function setUp() { $this->setupTheme(); } + /** + * Tests getting the theme registry defined by a module. + */ public function testGetRegistryForModule() { $this->setupTheme('test_theme'); $this->registry->setTheme((object) array(