/** * {@inheritdoc} */ public function evaluate() { if (!$this->configuration['theme']) { return TRUE; } return $this->themeNegotiator->determineActiveTheme($this->routeMatch) == $this->configuration['theme']; }
/** * Page callback: Tests the theme negotiation functionality. * * @param bool $inherited * TRUE when the requested page is intended to inherit * the theme of its parent. * * @return string * A string describing the requested custom theme and actual * theme being used * for the current page request. */ public function themePage($inherited) { $theme_key = $this->themeManager->getActiveTheme()->getName(); // Now we check what the theme negotiator service returns. $active_theme = $this->themeNegotiator->determineActiveTheme($this->routeMatch); $output = "Active theme: {$active_theme}. Actual theme: {$theme_key}."; if ($inherited) { $output .= ' Theme negotiation inheritance is being tested.'; } return ['#markup' => $output]; }
/** * Initializes the active theme for a given route match. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. */ protected function initTheme(RouteMatchInterface $route_match = NULL) { // Determine the active theme for the theme negotiator service. This includes // the default theme as well as really specific ones like the ajax base theme. if (!$route_match) { $route_match = \Drupal::routeMatch(); } if ($route_match instanceof StackedRouteMatchInterface) { $route_match = $route_match->getMasterRouteMatch(); } $theme = $this->themeNegotiator->determineActiveTheme($route_match); $this->activeTheme = $this->themeInitialization->initTheme($theme); }
/** * Gets the current theme for this page. * * @return string * The current theme. */ protected function getTheme() { return $this->themeNegotiator->determineActiveTheme($this->routeMatch); }