You are here

private function AdminSettingsForm::getUserRoles in Role Theme Switcher 8

Generates a list of roles.

Return value

array[] An array represent a list of roles ordered by weight.

1 call to AdminSettingsForm::getUserRoles()
AdminSettingsForm::buildForm in src/Form/AdminSettingsForm.php
Form constructor.

File

src/Form/AdminSettingsForm.php, line 148

Class

AdminSettingsForm
Provides the theme switcher configuration form.

Namespace

Drupal\role_theme_switcher\Form

Code

private function getUserRoles() {
  $values = [];
  $config = $this
    ->config('role_theme_switcher.settings')
    ->get('roles');
  $roles = user_role_names();
  foreach ($roles as $rid => $name) {
    $values[$rid] = [
      'rid' => $rid,
      'name' => $name,
      'weight' => $config[$rid]['weight'] ? $config[$rid]['weight'] : 0,
      'theme' => $config[$rid]['theme'] ? $config[$rid]['theme'] : '',
    ];
  }

  // Properly order all rows by weight.
  uasort($values, [
    'Drupal\\Component\\Utility\\SortArray',
    'sortByWeightElement',
  ]);
  return $values;
}