Commit 74eb2b9b authored by alexpott's avatar alexpott

Issue #2371725 by dawehner: Fixed Don't use theme negotiation all over the place.

parent 08d3ebba
......@@ -25,7 +25,7 @@ services:
- { name: cache.context}
cache_context.theme:
class: Drupal\Core\Cache\ThemeCacheContext
arguments: ['@current_route_match', '@theme.negotiator']
arguments: ['@theme.manager']
tags:
- { name: cache.context}
cache_context.timezone:
......
......@@ -8,7 +8,7 @@
namespace Drupal\Core\Cache;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
/**
* Defines the ThemeCacheContext service, for "per theme" caching.
......@@ -16,30 +16,20 @@
class ThemeCacheContext implements CacheContextInterface {
/**
* The current route match.
* The theme manager.
*
* @var \Drupal\Core\Routing\RouteMatch
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $routeMatch;
/**
* The theme negotiator.
*
* @var \Drupal\Core\Theme\ThemeNegotiator
*/
protected $themeNegotiator;
protected $themeManager;
/**
* Constructs a new ThemeCacheContext service.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\Theme\ThemeNegotiatorInterface $theme_negotiator
* The theme negotiator.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
*/
public function __construct(RouteMatchInterface $route_match, ThemeNegotiatorInterface $theme_negotiator) {
$this->routeMatch = $route_match;
$this->themeNegotiator = $theme_negotiator;
public function __construct(ThemeManagerInterface $theme_manager) {
$this->themeManager = $theme_manager;
}
/**
......@@ -53,7 +43,7 @@ public static function getLabel() {
* {@inheritdoc}
*/
public function getContext() {
return $this->themeNegotiator->determineActiveTheme($this->routeMatch) ?: 'stark';
return $this->themeManager->getActiveTheme()->getName() ?: 'stark';
}
}
......@@ -11,8 +11,7 @@
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -26,11 +25,11 @@
class CurrentThemeCondition extends ConditionPluginBase implements ContainerFactoryPluginInterface {
/**
* The theme negotiator.
* The theme manager.
*
* @var \Drupal\Core\Theme\ThemeNegotiatorInterface
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeNegotiator;
protected $themeManager;
/**
* The theme handler.
......@@ -39,13 +38,6 @@ class CurrentThemeCondition extends ConditionPluginBase implements ContainerFact
*/
protected $themeHandler;
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Constructs a CurrentThemeCondition condition plugin.
*
......@@ -55,18 +47,15 @@ class CurrentThemeCondition extends ConditionPluginBase implements ContainerFact
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Theme\ThemeNegotiatorInterface $theme_negotiator
* The theme negotiator.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ThemeNegotiatorInterface $theme_negotiator, ThemeHandlerInterface $theme_handler, RouteMatchInterface $route_match) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ThemeManagerInterface $theme_manager, ThemeHandlerInterface $theme_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->themeNegotiator = $theme_negotiator;
$this->themeManager = $theme_manager;
$this->themeHandler = $theme_handler;
$this->routeMatch = $route_match;
}
/**
......@@ -77,9 +66,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('theme.negotiator'),
$container->get('theme_handler'),
$container->get('current_route_match')
$container->get('theme.manager'),
$container->get('theme_handler')
);
}
......@@ -121,7 +109,7 @@ public function evaluate() {
return TRUE;
}
return $this->themeNegotiator->determineActiveTheme($this->routeMatch) == $this->configuration['theme'];
return $this->themeManager->getActiveTheme()->getName() == $this->configuration['theme'];
}
/**
......
......@@ -45,6 +45,8 @@ public function testCurrentTheme() {
// Set the expected theme to be used.
\Drupal::config('system.theme')->set('default', 'test_theme')->save();
\Drupal::theme()->resetActiveTheme();
$this->assertTrue($condition->execute());
$this->assertFalse($condition_negated->execute());
}
......
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