ThemeNegotiator.php in Drupal 9
File
core/lib/Drupal/Core/Theme/ThemeNegotiator.php
View source
<?php
namespace Drupal\Core\Theme;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\Routing\RouteMatchInterface;
class ThemeNegotiator implements ThemeNegotiatorInterface {
protected $negotiators = [];
protected $themeAccess;
protected $classResolver;
public function __construct(ThemeAccessCheck $theme_access, ClassResolverInterface $class_resolver, array $negotiators) {
$this->themeAccess = $theme_access;
$this->negotiators = $negotiators;
$this->classResolver = $class_resolver;
}
public function applies(RouteMatchInterface $route_match) {
return TRUE;
}
public function determineActiveTheme(RouteMatchInterface $route_match) {
foreach ($this->negotiators as $negotiator_id) {
$negotiator = $this->classResolver
->getInstanceFromDefinition($negotiator_id);
if ($negotiator
->applies($route_match)) {
$theme = $negotiator
->determineActiveTheme($route_match);
if ($theme !== NULL && $this->themeAccess
->checkAccess($theme)) {
return $theme;
}
}
}
}
}
Classes
Name |
Description |
ThemeNegotiator |
Provides a class which determines the active theme of the page. |