diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 805457c..3d1da49 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -85,7 +85,7 @@ function drupal_theme_access($theme) { * Initializes the theme system by loading the theme. */ function drupal_theme_initialize() { - global $theme, $user, $theme_key; + global $theme, $theme_key; // If $theme is already set, assume the others are set, too, and do nothing if (isset($theme)) { diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php index 4bd88ee..12231f2 100644 --- a/core/lib/Drupal/Core/CoreServiceProvider.php +++ b/core/lib/Drupal/Core/CoreServiceProvider.php @@ -93,13 +93,15 @@ protected function registerModuleHandler(ContainerBuilder $container) { if ($container->getParameter('kernel.environment') == 'install') { // During installation we use the non-cached version. $container->register('module_handler', 'Drupal\Core\Extension\ModuleHandler') - ->addArgument('%container.modules%'); + ->addArgument('%container.modules%') + ->addMethodCall('setThemeNegotiator', array(new Reference('theme.negotiator'))); } else { $container->register('module_handler', 'Drupal\Core\Extension\CachedModuleHandler') ->addArgument('%container.modules%') ->addArgument(new Reference('state')) - ->addArgument(new Reference('cache.bootstrap')); + ->addArgument(new Reference('cache.bootstrap')) + ->addMethodCall('setThemeNegotiator', array(new Reference('theme.negotiator'))); } } diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 92cf2a4..2f35df1 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Extension; use Drupal\Component\Graph\Graph; +use Drupal\Core\Theme\ThemeNegotiatorInterface; use Symfony\Component\Yaml\Parser; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\CacheBackendInterface; @@ -65,6 +66,11 @@ class ModuleHandler implements ModuleHandlerInterface { protected $alterFunctions; /** + * @var \Drupal\Core\Theme\ThemeNegotiatorInterface + */ + protected $themeNegotiator; + + /** * Constructs a ModuleHandler object. * * @param array $module_list @@ -79,6 +85,10 @@ public function __construct(array $module_list = array()) { $this->moduleList = $module_list; } + public function setThemeNegotiator(ThemeNegotiatorInterface $theme_negotiator) { + $this->themeNegotiator = $theme_negotiator; + } + /** * Implements \Drupal\Core\Extension\ModuleHandlerInterface::load(). */ @@ -378,8 +388,9 @@ public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL) { } // Allow the theme to alter variables after the theme system has been // initialized. - global $theme, $base_theme_info; - if (isset($theme)) { + if ($this->themeNegotiator && $theme = $this->themeNegotiator->determineActiveTheme(\Drupal::request())) { + drupal_theme_initialize(); + global $base_theme_info; $theme_keys = array(); foreach ($base_theme_info as $base) { $theme_keys[] = $base->name; diff --git a/core/modules/user/user.services.yml b/core/modules/user/user.services.yml index c70cad1..6fb7d47 100644 --- a/core/modules/user/user.services.yml +++ b/core/modules/user/user.services.yml @@ -25,9 +25,3 @@ services: class: Drupal\user\EventSubscriber\MaintenanceModeSubscriber tags: - { name: event_subscriber } - theme.negotiator.user: - class: Drupal\user\Theme\UserNegotiator - arguments: ['@plugin.manager.entity', '@current_user'] - tags: - - { name: theme_negotiator, priority: 50 } -