You are here

function _role_expire_get_role in Role Expire 8

Same name and namespace in other branches
  1. 6 role_expire.module \_role_expire_get_role()
  2. 7 role_expire.module \_role_expire_get_role()
  3. 2.x role_expire.module \_role_expire_get_role()

Get valid roles.

Helper function.

Return value

array Array of roles.

1 call to _role_expire_get_role()
role_expire_add_expiration_input in ./role_expire.module
Add form element that accepts the role expiration time.

File

./role_expire.module, line 441
Role Expire module.

Code

function _role_expire_get_role() {
  $roles_out = [];
  $roles = user_roles(TRUE);
  unset($roles[AccountInterface::AUTHENTICATED_ROLE]);
  $enabled_roles = \Drupal::service('role_expire.api')
    ->getEnabledExpirationRoles();

  // Return in the same format as in D7 version to simplify D8 upgrade.
  foreach ($roles as $role) {
    if (in_array($role
      ->id(), $enabled_roles)) {
      $roles_out[$role
        ->id()] = $role
        ->label();
    }
  }
  return $roles_out;
}