class Role6

  1. 8.0.x lib/Drush/Role/Role6.php Role6
  2. 7.x lib/Drush/Role/Role6.php Role6




Expanded class hierarchy of Role6


Contains filters are case sensitive
Namesort descending Modifiers Type Description
Role6::$perms public property
Role6::delete public function Overrides RoleBase::delete
Role6::getModulePerms public function Overrides RoleBase::getModulePerms
Role6::getPerms public function Overrides RoleBase::getPerms
Role6::grant_permissions public function Overrides RoleBase::grant_permissions
Role6::revoke_permissions public function Overrides RoleBase::revoke_permissions
Role6::role_create public function Overrides RoleBase::role_create
Role6::updatePerms function
Role6::_admin_user_role_op function
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::getAllModulePerms 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.


lib/Drush/Role/Role6.php, line 5

View source
class Role6 extends RoleBase {
  public $perms = array();

  public function getPerms() {
    if (empty($this->perms)) {
      $perms = db_result(db_query("SELECT perm FROM {permission} pm LEFT JOIN {role} r ON r.rid = pm.rid WHERE r.rid = '%d'", $this->rid));
      $role_perms = explode(", ", $perms);
      $this->perms = array_filter($role_perms);
    return $this->perms;

  public function getModulePerms($module) {
    return module_invoke($module, 'perm');

  public function role_create($role_machine_name, $role_human_readable_name = '') {
    $this->_admin_user_role_op($role_machine_name, t('Add role'));
    return TRUE;

  public function delete() {
    $this->_admin_user_role_op($this->rid, t('Delete role'));

  function _admin_user_role_op($role_machine_name, $op) {
    // c.f.
    require_once (drupal_get_path('module', 'user') . "/");

    $form_id = "user_admin_new_role";
    $form_values = array();
    $form_values["name"] = $role_machine_name;
    $form_values["op"] = $op;
    $form_state = array();
    $form_state["values"] = $form_values;

    drupal_execute($form_id, $form_state);

  public function grant_permissions($perms_to_add) {
    $perms = $this->getPerms();
    $this->perms = array_unique(array_merge($this->perms, $perms_to_add));

  public function revoke_permissions($perms_to_remove) {
    $perms = $this->getPerms();
    $this->perms = array_diff($this->perms, $perms_to_remove);

  function updatePerms() {
    $new_perms = implode(", ", $this->perms);
    drush_op('db_query', "UPDATE {permission} SET perm = '%s' WHERE rid= %d", $new_perms, $this->rid);