You are here

public function RoleExpireApiService::getEnabledExpirationRoles in Role Expire 8

Same name and namespace in other branches
  1. 2.x src/RoleExpireApiService.php \Drupal\role_expire\RoleExpireApiService::getEnabledExpirationRoles()

Get rid of all enabled roles.

Return value

array Returns an array where the values are the enabled roles.

File

src/RoleExpireApiService.php, line 293

Class

RoleExpireApiService
Class RoleExpireApiService.

Namespace

Drupal\role_expire

Code

public function getEnabledExpirationRoles() {
  $out = [];
  $roleExpirationStatus = $this
    ->getRolesExpirationStatus();
  foreach ($roleExpirationStatus as $rid => $disabled) {
    if ($disabled == 0) {
      $out[] = $rid;
    }
  }
  if (empty($out)) {

    /*
     * If the module is just installed, configuration could be empty.
     * We should return all roles to have role expiration.
     */
    $roles = user_roles(TRUE);
    unset($roles[AccountInterface::AUTHENTICATED_ROLE]);
    foreach ($roles as $role) {
      $out[] = $role
        ->id();
    }
  }
  return $out;
}