You are here

public function StyleguideThemeNegotiator::applies in Style Guide 8

Same name and namespace in other branches
  1. 2.x src/Theme/StyleguideThemeNegotiator.php \Drupal\styleguide\Theme\StyleguideThemeNegotiator::applies()

Whether this theme negotiator should be used to set the theme.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match object.

Return value

bool TRUE if this negotiator should be used or FALSE to let other negotiators decide.

Overrides ThemeNegotiatorInterface::applies

File

src/Theme/StyleguideThemeNegotiator.php, line 59

Class

StyleguideThemeNegotiator
The Styleguide Theme Negotiator.

Namespace

Drupal\styleguide\Theme

Code

public function applies(RouteMatchInterface $route_match) {
  if (strpos($route_match
    ->getRouteName(), 'styleguide.') === FALSE) {
    return FALSE;
  }
  $themes = $this->themeHandler
    ->rebuildThemeData();
  foreach ($themes as &$theme) {
    if (!empty($theme->info['hidden'])) {
      continue;
    }
    if ($theme->status) {
      $route_name = $route_match
        ->getRouteName();
      if ($route_name == 'styleguide.' . $theme
        ->getName() || $route_name == 'styleguide.maintenance_page.' . $theme
        ->getName()) {
        $this->themeName = $theme
          ->getName();
        return TRUE;
      }
    }
  }
  return FALSE;
}