public function RoleNegotiator::applies in Role Based Theme Switcher 8
Same name and namespace in other branches
- 9.1.x src/Theme/RoleNegotiator.php \Drupal\role_based_theme_switcher\Theme\RoleNegotiator::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/ RoleNegotiator.php, line 64 
Class
- RoleNegotiator
- Sets the active theme on admin pages.
Namespace
Drupal\role_based_theme_switcher\ThemeCode
public function applies(RouteMatchInterface $route_match) {
  // Use this theme on a certain route.
  $change_theme = TRUE;
  $route = $this->routeMatch
    ->getRouteObject();
  $is_admin_route = $this->adminRoute
    ->isAdminRoute($route);
  if ($is_admin_route === TRUE && $this->account
    ->hasPermission('view the administration theme') === TRUE) {
    $change_theme = FALSE;
  }
  // Here you return the actual theme name.
  $roleThemes = $this->configFactory
    ->get('role_based_theme_switcher.RoleBasedThemeSwitchConfig')
    ->get('roletheme');
  // Get current roles a user has.
  $roles = $this->account
    ->getRoles();
  // Get highest role.
  $theme_role = $this
    ->getPriorityRole($roles);
  if (!empty($roleThemes[$theme_role]['id'])) {
    $this->theme = $roleThemes[$theme_role]['id'];
  }
  return $change_theme;
}