class Role8

  1. 8.0.x lib/Drush/Role/Role8.php Role8
  2. 7.x lib/Drush/Role/Role8.php Role8
  3. master lib/Drush/Role/Role8.php Role8

Namespace

Drush\Role

Hierarchy

Expanded class hierarchy of Role8

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
Role8::delete public function Overrides Role7::delete
Role8::getAllModulePerms public function Overrides RoleBase::getAllModulePerms
Role8::getModulePerms public function Overrides Role7::getModulePerms
Role8::getPerms public function Overrides Role7::getPerms
Role8::grant_permissions public function Overrides Role7::grant_permissions
Role8::revoke_permissions public function Overrides Role7::revoke_permissions
Role8::role_create public function Overrides Role7::role_create
RoleBase::$name public property Drupal 6 and Drupal 7: 'rid' is numeric 'name' is machine name (e.g. 'anonymous user')
RoleBase::$rid public property
RoleBase::$roles public property This is initialized to the result of the user_roles() function, which returns an associative array of rid => name pairs.
RoleBase::add public function
RoleBase::remove public function
RoleBase::__construct public function This constructor will allow the role to be selected either via the role id or via the role name.

File

lib/Drush/Role/Role8.php, line 7

View source
class Role8 extends Role7 {
  public function role_create($role_machine_name, $role_human_readable_name = '') {
    // In D6 and D7, when we create a new role, the role
    // machine name is specified, and the numeric rid is
    // auto-assigned (next available id); in D8, when we
    // create a new role, we need to specify both the rid,
    // which is now the role machine name, and also a human-readable
    // role name.  If the client did not provide a human-readable
    // name, then we'll use the role machine name in its place.
    if (empty($role_human_readable_name)) {
      $role_human_readable_name = ucfirst($role_machine_name);
    }
    $role = new Role(array(
      'id' => $role_machine_name,
      'label' => $role_human_readable_name,
    ), 'user_role');
    $role->save();
    return $role;
  }

  public function getPerms() {
    $role = entity_load('user_role', $this->rid);
    $perms = $role->getPermissions();
    // $perms = user_role_permissions(array($this->rid => $this->name));
    return $perms;
  }

  public function getAllModulePerms() {
    $perms = \Drupal::service('user.permissions')->getPermissions();
    return array_keys($perms);
  }

  public function getModulePerms($module) {
    $module_perms = array();
    $perms = \Drupal::service('user.permissions')->getPermissions();
    foreach ($perms as $name => $perm) {
      if ($perm['provider'] == $module) {
        $module_perms[] = $name;
      }
    }
    return $module_perms;
  }

  public function delete() {
    $role = entity_load('user_role', $this->rid);
    $role->delete();
  }

  public function grant_permissions($perms) {
    return drush_op('user_role_grant_permissions', $this->rid, $perms);
  }

  public function revoke_permissions($perms) {
    return drush_op('user_role_revoke_permissions', $this->rid, $perms);
  }
}