3 namespace Drupal\Core\Theme;
5 use Drupal\Core\DependencyInjection\ClassResolverInterface;
6 use Drupal\Core\Routing\RouteMatchInterface;
9 * Provides a class which determines the active theme of the page.
11 * It therefore uses ThemeNegotiatorInterface objects which are passed in
12 * using the 'theme_negotiator' tag.
14 class ThemeNegotiator implements ThemeNegotiatorInterface {
17 * Holds an array of theme negotiator IDs, sorted by priority.
21 protected $negotiators = [];
24 * The access checker for themes.
26 * @var \Drupal\Core\Theme\ThemeAccessCheck
28 protected $themeAccess;
33 * @var \Drupal\Core\DependencyInjection\ClassResolverInterface
35 protected $classResolver;
38 * Constructs a new ThemeNegotiator.
40 * @param \Drupal\Core\Theme\ThemeAccessCheck $theme_access
41 * The access checker for themes.
42 * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
44 * @param string[] $negotiators
45 * An array of negotiator IDs.
47 public function __construct(ThemeAccessCheck $theme_access, ClassResolverInterface $class_resolver, array $negotiators) {
48 $this->themeAccess = $theme_access;
49 $this->negotiators = $negotiators;
50 $this->classResolver = $class_resolver;
56 public function applies(RouteMatchInterface $route_match) {
63 public function determineActiveTheme(RouteMatchInterface $route_match) {
64 foreach ($this->negotiators as $negotiator_id) {
65 $negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id);
67 if ($negotiator->applies($route_match)) {
68 $theme = $negotiator->determineActiveTheme($route_match);
69 if ($theme !== NULL && $this->themeAccess->checkAccess($theme)) {