You are here

private function UserRole::getRoles in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Condition/UserRole.php \Drupal\rng\Plugin\Condition\UserRole::getRoles()
  2. 3.x src/Plugin/Condition/UserRole.php \Drupal\rng\Plugin\Condition\UserRole::getRoles()

Get a list of valid roles permitted by global settings.

Anonymous and authenticated roles are automatically removed.

Return value

array An array of role labels keyed by role ID.

3 calls to UserRole::getRoles()
UserRole::alterQuery in src/Plugin/Condition/UserRole.php
Modify a query with condition configuration.
UserRole::buildConfigurationForm in src/Plugin/Condition/UserRole.php
Form constructor.
UserRole::summary in src/Plugin/Condition/UserRole.php
Provides a human readable summary of the condition's configuration.

File

src/Plugin/Condition/UserRole.php, line 83

Class

UserRole
Provides a user role condition where all roles are matched.

Namespace

Drupal\rng\Plugin\Condition

Code

private function getRoles() {
  $options = [];
  foreach (Role::loadMultiple() as $role) {

    /** @var \Drupal\user\RoleInterface $role */
    if ($role
      ->getThirdPartySetting('rng', 'condition_rng_role', FALSE)) {
      $options[$role
        ->id()] = $role
        ->label();
    }
  }

  // If there are no roles enabled, then expose all roles.
  if (!count($options)) {
    $options = user_role_names(TRUE);
  }
  unset($options[AccountInterface::ANONYMOUS_ROLE]);
  unset($options[AccountInterface::AUTHENTICATED_ROLE]);
  return $options;
}