You are here

public function RoleNegotiator::getPriorityRole in Role Based Theme Switcher 8

Same name and namespace in other branches
  1. 9.1.x src/Theme/RoleNegotiator.php \Drupal\role_based_theme_switcher\Theme\RoleNegotiator::getPriorityRole()

Function to get roles array and return highest priority role.

Parameters

array $roles: Array of roles.

Return value

string Return role.

1 call to RoleNegotiator::getPriorityRole()
RoleNegotiator::applies in src/Theme/RoleNegotiator.php
Whether this theme negotiator should be used to set the theme.

File

src/Theme/RoleNegotiator.php, line 96

Class

RoleNegotiator
Sets the active theme on admin pages.

Namespace

Drupal\role_based_theme_switcher\Theme

Code

public function getPriorityRole(array $roles) {
  $themes = $this->configFactory
    ->get('role_based_theme_switcher.RoleBasedThemeSwitchConfig')
    ->get('roletheme');
  if (isset($themes)) {
    foreach ($themes as $key => $value) {
      if (in_array($key, $roles)) {
        $themeArr[$key] = $value['weight'];
      }
    }
    $priRole = array_search(max($themeArr), $themeArr);

    // Return role.
    return $priRole;
  }
}