Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Theme / ThemeNegotiator.php
1 <?php
2
3 namespace Drupal\Core\Theme;
4
5 use Drupal\Core\DependencyInjection\ClassResolverInterface;
6 use Drupal\Core\Routing\RouteMatchInterface;
7
8 /**
9  * Provides a class which determines the active theme of the page.
10  *
11  * It therefore uses ThemeNegotiatorInterface objects which are passed in
12  * using the 'theme_negotiator' tag.
13  */
14 class ThemeNegotiator implements ThemeNegotiatorInterface {
15
16   /**
17    * Holds an array of theme negotiator IDs, sorted by priority.
18    *
19    * @var string[]
20    */
21   protected $negotiators = [];
22
23   /**
24    * The access checker for themes.
25    *
26    * @var \Drupal\Core\Theme\ThemeAccessCheck
27    */
28   protected $themeAccess;
29
30   /**
31    * The class resolver.
32    *
33    * @var \Drupal\Core\DependencyInjection\ClassResolverInterface
34    */
35   protected $classResolver;
36
37   /**
38    * Constructs a new ThemeNegotiator.
39    *
40    * @param \Drupal\Core\Theme\ThemeAccessCheck $theme_access
41    *   The access checker for themes.
42    * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
43    *   The class resolver.
44    * @param string[] $negotiators
45    *   An array of negotiator IDs.
46    */
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;
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function applies(RouteMatchInterface $route_match) {
57     return TRUE;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function determineActiveTheme(RouteMatchInterface $route_match) {
64     foreach ($this->negotiators as $negotiator_id) {
65       $negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id);
66
67       if ($negotiator->applies($route_match)) {
68         $theme = $negotiator->determineActiveTheme($route_match);
69         if ($theme !== NULL && $this->themeAccess->checkAccess($theme)) {
70           return $theme;
71         }
72       }
73     }
74   }
75
76 }