diff --git a/core/config/install/core.extension.yml b/core/config/install/core.extension.yml index debc391..eae39ef 100644 --- a/core/config/install/core.extension.yml +++ b/core/config/install/core.extension.yml @@ -1,6 +1,5 @@ module: {} theme: - seven: 0 stark: 0 disabled: theme: {} diff --git a/core/includes/common.inc b/core/includes/common.inc index 9bfc20a..73e2c4c 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4058,7 +4058,7 @@ function drupal_flush_all_caches() { // use it. Unlike regular usages of this function, the installer and update // scripts need to flush all caches during GET requests/page building. if (function_exists('_drupal_maintenance_theme')) { - unset($GLOBALS['theme']); + \Drupal::theme()->resetActiveTheme(); drupal_maintenance_theme(); } } diff --git a/core/includes/errors.inc b/core/includes/errors.inc index bb5448b..51add03 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -126,12 +126,11 @@ function _drupal_log_error($error, $fatal = FALSE) { // point in time already. Do not unset that. if (!$is_installer) { \Drupal::theme()->setActiveTheme(NULL); - unset($GLOBALS['theme']); } if (!defined('MAINTENANCE_MODE')) { define('MAINTENANCE_MODE', 'error'); } - // No-op if $GLOBALS['theme'] is set already. + // No-op if the active theme is set already. drupal_maintenance_theme(); } diff --git a/core/includes/theme.maintenance.inc b/core/includes/theme.maintenance.inc index f9c41c3..2adb930 100644 --- a/core/includes/theme.maintenance.inc +++ b/core/includes/theme.maintenance.inc @@ -19,10 +19,8 @@ * setting a "maintenance_theme" key in the $settings variable in settings.php. */ function _drupal_maintenance_theme() { - global $theme, $theme_key; - - // If $theme is already set, assume the others are set too, and do nothing. - if (isset($theme)) { + // If the theme is already set, assume the others are set too, and do nothing. + if (\Drupal::theme()->hasActiveTheme()) { return; } @@ -92,9 +90,6 @@ function _drupal_maintenance_theme() { // list_themes() builds its cache. $theme = $custom_theme; - // Store the identifier for retrieving theme settings with. - $theme_key = $theme; - // Find all our ancestor themes and put them in an array. $base_theme = array(); $ancestor = $theme; diff --git a/core/lib/Drupal/Core/Theme/ThemeManager.php b/core/lib/Drupal/Core/Theme/ThemeManager.php index 5c4ce84..de41361 100644 --- a/core/lib/Drupal/Core/Theme/ThemeManager.php +++ b/core/lib/Drupal/Core/Theme/ThemeManager.php @@ -76,6 +76,20 @@ public function getActiveTheme(RouteMatchInterface $route_match = NULL) { /** * {@inheritdoc} */ + public function hasActiveTheme() { + return isset($this->activeTheme); + } + + /** + * @TODO + */ + public function resetActiveTheme() { + $this->activeTheme = NULL; + } + + /** + * {@inheritdoc} + */ public function setActiveTheme(ActiveTheme $active_theme) { $this->activeTheme = $active_theme; if ($active_theme) { diff --git a/core/lib/Drupal/Core/Theme/ThemeManagerInterface.php b/core/lib/Drupal/Core/Theme/ThemeManagerInterface.php index e3d851f..0d11a39 100644 --- a/core/lib/Drupal/Core/Theme/ThemeManagerInterface.php +++ b/core/lib/Drupal/Core/Theme/ThemeManagerInterface.php @@ -33,6 +33,16 @@ public function render($hook, $variables); */ public function getActiveTheme(); + /** + * @TODO + */ + public function hasActiveTheme(); + + /** + * @TODO + */ + public function resetActiveTheme(); + public function setActiveTheme(ActiveTheme $active_theme); /** diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php index 1b26b9f..dd171f9 100644 --- a/core/modules/block/src/BlockListBuilder.php +++ b/core/modules/block/src/BlockListBuilder.php @@ -87,7 +87,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI public function load() { // If no theme was specified, use the current theme. if (!$this->theme) { - $this->theme = $GLOBALS['theme']; + $this->theme = \Drupal::theme()->getActiveTheme()->getName(); } // Store the region list. @@ -117,7 +117,7 @@ public function load() { public function render($theme = NULL, Request $request = NULL) { $this->request = $request; // If no theme was specified, use the current theme. - $this->theme = $theme ?: $GLOBALS['theme_key']; + $this->theme = $theme ?: \Drupal::theme()->getActiveTheme()->getName(); return \Drupal::formBuilder()->getForm($this); } diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 3577a8d..663a92c 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -97,7 +97,7 @@ function color_css_alter(&$css) { * Replace the logo with the colored version if available. */ function color_preprocess_page(&$variables) { - global $theme_key; + $theme_key = \Drupal::theme()->getActiveTheme()->getName(); // Override logo. $logo = \Drupal::config('color.theme.' . $theme_key)->get('logo'); diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index afe1feb..4e89fd6 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -1080,12 +1080,6 @@ private function prepareEnvironment() { unset($GLOBALS['config_directories']); unset($GLOBALS['config']); unset($GLOBALS['conf']); - unset($GLOBALS['theme_key']); - unset($GLOBALS['theme']); - unset($GLOBALS['theme_info']); - unset($GLOBALS['base_theme_info']); - unset($GLOBALS['theme_engine']); - unset($GLOBALS['theme_path']); // Log fatal errors. ini_set('log_errors', 1); @@ -1186,14 +1180,6 @@ private function restoreEnvironment() { // this second reset is guaranteed to reset everything to nothing. drupal_static_reset(); - // Reset global theme variables. - unset($GLOBALS['theme_key']); - unset($GLOBALS['theme']); - unset($GLOBALS['theme_info']); - unset($GLOBALS['base_theme_info']); - unset($GLOBALS['theme_engine']); - unset($GLOBALS['theme_path']); - // Restore original in-memory configuration. $GLOBALS['config'] = $this->originalConfig; $GLOBALS['conf'] = $this->originalConf; diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index af52b04..ceaf612 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -284,8 +284,11 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme = // Save the name of the current theme (if any), so that we can temporarily // override the current theme and allow theme_get_setting() to work // without having to pass the theme name to it. - $default_theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : NULL; - $GLOBALS['theme_key'] = $theme; + $default_active_theme = \Drupal::theme()->getActiveTheme(); + $default_theme = $default_active_theme->getName(); + /** @var \Drupal\Core\Theme\Initialization $theme_initialization */ + $theme_initialization = \Drupal::service('theme.initialization'); + \Drupal::theme()->setActiveTheme($theme_initialization->getActiveThemeByName($theme)); // Process the theme and all its base themes. foreach ($theme_keys as $theme) { @@ -304,10 +307,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme = // Restore the original current theme. if (isset($default_theme)) { - $GLOBALS['theme_key'] = $default_theme; + \Drupal::theme()->setActiveTheme($default_theme); } else { - unset($GLOBALS['theme_key']); + \Drupal::theme()->setActiveTheme(NULL); } } diff --git a/core/modules/system/src/Tests/Common/RegionContentTest.php b/core/modules/system/src/Tests/Common/RegionContentTest.php index 6b2d3a4..51ea973 100644 --- a/core/modules/system/src/Tests/Common/RegionContentTest.php +++ b/core/modules/system/src/Tests/Common/RegionContentTest.php @@ -19,7 +19,7 @@ class RegionContentTest extends WebTestBase { * Tests setting and retrieving content for theme regions. */ function testRegions() { - global $theme_key; + $theme_key = \Drupal::theme()->getActiveTheme()->getName(); $block_regions = array_keys(system_region_list($theme_key)); $delimiter = $this->randomName(32); diff --git a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php index 08c07b7..ff02186 100644 --- a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -328,7 +328,7 @@ public function generateOutputKey() { 'result' => $this->view->result, 'roles' => $user->getRoles(), 'super-user' => $user->id() == 1, // special caching for super user. - 'theme' => $GLOBALS['theme'], + 'theme' => \Drupal::theme()->getActiveTheme()->getName(), 'langcode' => \Drupal::languageManager()->getCurrentLanguage()->id, 'base_url' => $GLOBALS['base_url'], );