3 namespace Drupal\webprofiler\Theme;
5 use Drupal\Core\Routing\RouteMatchInterface;
6 use Drupal\Core\Theme\ThemeNegotiator;
9 * Class ThemeNegotiatorWrapper
11 class ThemeNegotiatorWrapper extends ThemeNegotiator {
14 * @var \Drupal\Core\Theme\ThemeNegotiatorInterface
21 public function determineActiveTheme(RouteMatchInterface $route_match) {
22 // This method has changed in Drupal 8.4.x, to maintain compatibility with
23 // Drupal 8.3.x we check the existence or not of the classResolver
25 // TODO: remove this logic when we decide to drop Drupal 8.3.x support.
26 if (property_exists($this, 'classResolver')) {
27 $classResolver = $this->classResolver;
28 $negotiators = $this->negotiators;
30 $classResolver = \Drupal::classResolver();
31 $negotiators = $this->getSortedNegotiators();
34 foreach ($negotiators as $negotiator_id) {
35 if (property_exists($this, 'classResolver')) {
36 $negotiator = $classResolver->getInstanceFromDefinition($negotiator_id);
38 $negotiator = $negotiator_id;
41 if ($negotiator->applies($route_match)) {
42 $theme = $negotiator->determineActiveTheme($route_match);
43 if ($theme !== NULL && $this->themeAccess->checkAccess($theme)) {
44 $this->negotiator = $negotiator;
52 * @return \Drupal\Core\Theme\ThemeNegotiatorInterface
54 public function getNegotiator() {
55 return $this->negotiator;
59 * Returns the sorted array of theme negotiators.
61 * @return array|\Drupal\Core\Theme\ThemeNegotiatorInterface[]
62 * An array of theme negotiator objects.
64 * TODO: remove this method when we decide to drop Drupal 8.3.x support.
66 protected function getSortedNegotiators() {
67 if (!isset($this->sortedNegotiators)) {
68 // Sort the negotiators according to priority.
69 krsort($this->negotiators);
70 // Merge nested negotiators from $this->negotiators into
71 // $this->sortedNegotiators.
72 $this->sortedNegotiators = [];
73 foreach ($this->negotiators as $builders) {
74 $this->sortedNegotiators = array_merge($this->sortedNegotiators, $builders);
77 return $this->sortedNegotiators;