You are here

public function AdministerusersbyrolePermissions::permissions in Administer Users by Role 8.2

Same name and namespace in other branches
  1. 8.3 src/AdministerusersbyrolePermissions.php \Drupal\administerusersbyrole\AdministerusersbyrolePermissions::permissions()

Returns an array of administerusersbyrole permissions.

Return value

array

1 string reference to 'AdministerusersbyrolePermissions::permissions'
administerusersbyrole.permissions.yml in ./administerusersbyrole.permissions.yml
administerusersbyrole.permissions.yml

File

src/AdministerusersbyrolePermissions.php, line 29

Class

AdministerusersbyrolePermissions
Provides dynamic permissions of the administerusersbyrole module.

Namespace

Drupal\administerusersbyrole

Code

public function permissions() {
  $roles = user_roles(TRUE);
  $perms = [];
  $ops = array(
    'edit' => t('Edit'),
    'cancel' => t('Cancel'),
  );
  foreach ($roles as $rid => $role) {
    if ($role
      ->isAdmin()) {

      // Exclude the admin role.  Once you can edit an admin, you can set their password, log in and do anything,
      // which defeats the point of using this module.
      continue;
    }
    foreach ($ops as $op => $operation) {
      $perm_string = _administerusersbyrole_build_perm_string($rid, $op);
      if ($rid == AccountInterface::AUTHENTICATED_ROLE) {
        $perm_title = $this
          ->t("@operation users with no custom roles", array(
          '@operation' => $operation,
        ));
      }
      else {
        $perm_title = $this
          ->t("@operation users with role %role", array(
          '@operation' => $operation,
          '%role' => $role
            ->label(),
        ));
      }
      $perms[$perm_string] = array(
        'title' => $perm_title,
      );
    }
  }
  return $perms;
}