You are here

public function RoleThemeSwitcherNegotiator::applies in Role Theme Switcher 8

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/RoleThemeSwitcherNegotiator.php, line 70

Class

RoleThemeSwitcherNegotiator
Class RoleThemeSwitcherNegotiator.

Namespace

Drupal\role_theme_switcher\Theme

Code

public function applies(RouteMatchInterface $route_match) {
  $roles = $this->configFactory
    ->get('role_theme_switcher.settings')
    ->get('roles');
  if ($roles) {

    // Properly order all rows by weight.
    uasort($roles, [
      'Drupal\\Component\\Utility\\SortArray',
      'sortByWeightElement',
    ]);
    $user_roles = $this->currentUser
      ->getRoles();
    foreach ($roles as $rid => $config) {
      if (in_array($rid, $user_roles)) {
        $this->theme = $config['theme'];
        break;
      }
    }
  }

  // Return TRUE if there is a theme to activate and the current page is not
  // an admin page.
  return $this->theme && !$this->adminContext
    ->isAdminRoute($route_match
    ->getRouteObject());
}