diff --git a/core/core.services.yml b/core/core.services.yml index 224222b..6568923 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -665,6 +665,8 @@ services: theme.initialisation: class: Drupal\Core\Theme\Initialisation arguments: ['@theme_handler', '@theme.negotiator'] + calls: + - [setRequest, ['@?request=']] theme.registry: class: Drupal\Core\Theme\Registry arguments: ['@cache.cache', '@lock', '@module_handler'] diff --git a/core/lib/Drupal/Core/Theme/DefaultNegotiator.php b/core/lib/Drupal/Core/Theme/DefaultNegotiator.php index b08882d..94dc4e6 100644 --- a/core/lib/Drupal/Core/Theme/DefaultNegotiator.php +++ b/core/lib/Drupal/Core/Theme/DefaultNegotiator.php @@ -16,11 +16,11 @@ class DefaultNegotiator implements ThemeNegotiatorInterface { /** - * The system theme config object. + * The config factory * - * @var \Drupal\Core\Config\Config + * @var \Drupal\Core\Config\ConfigFactory */ - protected $config; + protected $configFactory; /** * Constructs a DefaultNegotiator object. @@ -29,7 +29,7 @@ class DefaultNegotiator implements ThemeNegotiatorInterface { * The config factory. */ public function __construct(ConfigFactory $config_factory) { - $this->config = $config_factory->get('system.theme'); + $this->configFactory = $config_factory; } /** @@ -43,7 +43,7 @@ public function applies(Request $request) { * {@inheritdoc} */ public function determineActiveTheme(Request $request) { - return $this->config->get('default'); + return $this->configFactory->get('system.theme')->get('default'); } } diff --git a/core/lib/Drupal/Core/Theme/Initialisation.php b/core/lib/Drupal/Core/Theme/Initialisation.php index 53a4c09..688c4b4 100644 --- a/core/lib/Drupal/Core/Theme/Initialisation.php +++ b/core/lib/Drupal/Core/Theme/Initialisation.php @@ -8,15 +8,57 @@ namespace Drupal\Core\Theme; use Drupal\Core\Extension\ThemeHandlerInterface; +use Symfony\Component\HttpFoundation\Request; +/** + * Provides the theme initialisation logic. + */ class Initialisation { + /** + * The theme handler. + * + * @var \Drupal\Core\Extension\ThemeHandlerInterface + */ + protected $themeHandler; + /** + * The theme negotiator. + * + * @var \Drupal\Core\Theme\ThemeNegotiator + */ + protected $themeNegotiator; + + /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** + * Constructs a new Initialisation instance. + * + * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler + * The theme handler. + * @param \Drupal\Core\Theme\ThemeNegotiator $theme_negotiator + * The theme negotiator. + */ public function __construct(ThemeHandlerInterface $theme_handler, ThemeNegotiator $theme_negotiator) { $this->themeHandler = $theme_handler; $this->themeNegotiator = $theme_negotiator; } + /** + * Sets the current theme. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. + */ + public function setRequest(Request $request) { + $this->request = $request; + } + public function initThemeSystem() { global $theme, $theme_key; @@ -30,8 +72,7 @@ public function initThemeSystem() { // @todo Let the theme.negotiator listen to the kernel request event. // Determine the active theme for the theme negotiator service. This includes // the default theme as well as really specific ones like the ajax base theme. - $request = \Drupal::request(); - $theme = $this->themeNegotiator->determineActiveTheme($request) ?: 'stark'; + $theme = $this->themeNegotiator->determineActiveTheme($this->request) ?: 'stark'; // Store the identifier for retrieving theme settings with. $theme_key = $theme; @@ -225,4 +266,4 @@ public function loadIncludes($theme, $base_theme) { return $theme_engine; } -} +}