You are here

function user_role_grant_permissions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/user.module \user_role_grant_permissions()

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()

34 calls to user_role_grant_permissions()
AccessDeniedTest::setUp in core/modules/system/src/Tests/System/AccessDeniedTest.php
Sets up a Drupal site for running functional and integration tests.
BookTest::testBookExport in core/modules/book/src/Tests/BookTest.php
Tests book export ("printer-friendly version") functionality.
BreadcrumbTest::testBreadCrumbs in core/modules/system/src/Tests/Menu/BreadcrumbTest.php
Tests breadcrumbs on node and administrative paths.
BrowserTestBase::drupalCreateRole in core/modules/simpletest/src/BrowserTestBase.php
Creates a role with specified permissions.
CommentAdminTest::testEditComment in core/modules/comment/src/Tests/CommentAdminTest.php
Tests editing a comment as an admin.

... See full list

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();
  }
}