Commit d305a8ef authored by alexpott's avatar alexpott
Browse files

Issue #2499943 by mikey_p, Berdir, catch: system.active_theme.THEMENAME state...

Issue #2499943 by mikey_p, Berdir, catch: system.active_theme.THEMENAME state should not cache theme data
parent 337f1820
......@@ -1216,7 +1216,7 @@ services:
- [setThemeRegistry, ['@theme.registry']]
theme.initialization:
class: Drupal\Core\Theme\ThemeInitialization
arguments: ['@app.root', '@theme_handler', '@state', '@module_handler']
arguments: ['@app.root', '@theme_handler', '@cache.bootstrap', '@module_handler']
theme.registry:
class: Drupal\Core\Theme\Registry
arguments: ['@app.root', '@cache.default', '@lock', '@module_handler', '@theme_handler', '@theme.initialization']
......
......@@ -1304,13 +1304,6 @@ function drupal_flush_all_caches() {
/** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
$theme_handler = \Drupal::service('theme_handler');
$theme_handler->refreshInfo();
// Remove the cache of the active theme's info file information in state.
// @see \Drupal\Core\Theme\ThemeInitialization::getActiveByThemeName()
$keys = [];
foreach ($theme_handler->listInfo() as $theme_name => $theme) {
$keys[] = 'theme.active_theme.' . $theme_name;
}
\Drupal::state()->deleteMultiple($keys);
// In case the active theme gets requested later in the same request we need
// to reset the theme manager.
\Drupal::theme()->resetActiveTheme();
......
......@@ -7,10 +7,10 @@
namespace Drupal\Core\Theme;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\State\StateInterface;
/**
* Provides the theme initialization logic.
......@@ -25,11 +25,11 @@ class ThemeInitialization implements ThemeInitializationInterface {
protected $themeHandler;
/**
* The state.
* The cache backend to use for the active theme.
*
* @var \Drupal\Core\State\StateInterface
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $state;
protected $cache;
/**
* The app root.
......@@ -52,15 +52,15 @@ class ThemeInitialization implements ThemeInitializationInterface {
* The app root.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
* @param \Drupal\Core\State\StateInterface $state
* The state.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to use to load modules.
*/
public function __construct($root, ThemeHandlerInterface $theme_handler, StateInterface $state, ModuleHandlerInterface $module_handler) {
public function __construct($root, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler) {
$this->root = $root;
$this->themeHandler = $theme_handler;
$this->state = $state;
$this->cache = $cache;
$this->moduleHandler = $module_handler;
}
......@@ -78,8 +78,8 @@ public function initTheme($theme_name) {
* {@inheritdoc}
*/
public function getActiveThemeByName($theme_name) {
if ($active_theme = $this->state->get('theme.active_theme.' . $theme_name)) {
return $active_theme;
if ($cached = $this->cache->get('theme.active_theme.' . $theme_name)) {
return $cached->data;
}
$themes = $this->themeHandler->listInfo();
......@@ -114,7 +114,7 @@ public function getActiveThemeByName($theme_name) {
$active_theme = $this->getActiveTheme($themes[$theme_name], $base_themes);
$this->state->set('theme.active_theme.' . $theme_name, $active_theme);
$this->cache->set('theme.active_theme.' . $theme_name, $active_theme);
return $active_theme;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment