diff -u b/core/lib/Drupal/Core/Utility/ThemeRegistry.php b/core/lib/Drupal/Core/Utility/ThemeRegistry.php --- b/core/lib/Drupal/Core/Utility/ThemeRegistry.php +++ b/core/lib/Drupal/Core/Utility/ThemeRegistry.php @@ -12,6 +12,7 @@ use Drupal\Core\Cache\CacheCollector; use Drupal\Core\DestructableInterface; use Drupal\Core\Lock\LockBackendInterface; +use Symfony\Component\HttpFoundation\RequestStack; /** * Builds the run-time theme registry. @@ -64,17 +65,20 @@ * The cache backend. * @param \Drupal\Core\Lock\LockBackendInterface $lock * The lock backend. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack. * @param array $tags * (optional) The tags to specify for the cache item. * @param bool $modules_loaded * Whether all modules have already been loaded. */ - function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, $tags = array(), $modules_loaded = FALSE) { + function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, RequestStack $request_stack, $tags = array(), $modules_loaded = FALSE) { $this->cache = $cache; $this->lock = $lock; $this->tags = $tags; $this->cid = $cid; $this->modulesLoaded = $modules_loaded; + $this->requestStack = $request_stack; } /** @@ -84,7 +88,7 @@ */ protected function getPersistable() { if ($this->persistable === NULL) { - $this->persistable = $this->modulesLoaded && \Drupal::hasRequest() && \Drupal::request()->isMethod('GET'); + $this->persistable = $this->modulesLoaded && $this->requestStack->getCurrentRequest() !== NULL && $this->requestStack->getCurrentRequest()->isMethod('GET'); } return $this->persistable; only in patch2: unchanged: --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1193,7 +1193,7 @@ services: arguments: ['@app.root', '@theme_handler', '@state', '@module_handler'] theme.registry: class: Drupal\Core\Theme\Registry - arguments: ['@app.root', '@cache.default', '@lock', '@module_handler', '@theme_handler', '@theme.initialization'] + arguments: ['@app.root', '@cache.default', '@lock', '@module_handler', '@theme_handler', '@theme.initialization', '@request_stack'] tags: - { name: needs_destruction } calls: only in patch2: unchanged: --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -14,6 +14,7 @@ use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Utility\ThemeRegistry; +use Symfony\Component\HttpFoundation\RequestStack; /** * Defines the theme registry service. @@ -138,6 +139,13 @@ class Registry implements DestructableInterface { protected $themeManager; /** + * The related request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + + /** * Constructs a \Drupal\Core\Theme\Registry object. * * @param string $root @@ -152,10 +160,12 @@ class Registry implements DestructableInterface { * The theme handler. * @param \Drupal\Core\Theme\ThemeInitializationInterface $theme_initialization * The theme initialization. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack. * @param string $theme_name * (optional) The name of the theme for which to construct the registry. */ - public function __construct($root, CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeInitializationInterface $theme_initialization, $theme_name = NULL) { + public function __construct($root, CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeInitializationInterface $theme_initialization, RequestStack $request_stack, $theme_name = NULL) { $this->root = $root; $this->cache = $cache; $this->lock = $lock; @@ -163,6 +173,7 @@ public function __construct($root, CacheBackendInterface $cache, LockBackendInte $this->themeName = $theme_name; $this->themeHandler = $theme_handler; $this->themeInitialization = $theme_initialization; + $this->requestStack = $request_stack; } /** @@ -236,7 +247,7 @@ public function get() { public function getRuntime() { $this->init($this->themeName); if (!isset($this->runtimeRegistry)) { - $this->runtimeRegistry = new ThemeRegistry('theme_registry:runtime:' . $this->theme->getName(), $this->cache, $this->lock, array('theme_registry'), $this->moduleHandler->isLoaded()); + $this->runtimeRegistry = new ThemeRegistry('theme_registry:runtime:' . $this->theme->getName(), $this->cache, $this->lock, $this->requestStack, array('theme_registry'), $this->moduleHandler->isLoaded()); } return $this->runtimeRegistry; }