function user_role_grant_permissions

user_role_grant_permissions($rid, array $permissions = array())

Grant permissions to a user role.

Parameters

mixed $rid: The ID of a user role to alter.

array $permissions: (optional) A list of permission names to grant.

See also

user_role_change_permissions()

user_role_revoke_permissions()

File

core/modules/user/user.module, line 1137
Enables the user registration and login system.

Code

function user_role_grant_permissions($rid, array $permissions = array()) {
  // Grant new permissions for the role.
  if ($role = Role::load($rid)) {
    foreach ($permissions as $permission) {
      $role->grantPermission($permission);
    }
    $role->trustData()->save();
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!user!user.module/function/user_role_grant_permissions/8.1.x