function user_role_grant_permissions

Same name in other branches
  1. 7.x modules/user/user.module \user_role_grant_permissions()
  2. 8.9.x core/modules/user/user.module \user_role_grant_permissions()
  3. 10 core/modules/user/user.module \user_role_grant_permissions()
  4. 11.x 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()

36 calls to user_role_grant_permissions()
AccessDeniedTest::setUp in core/modules/system/tests/src/Functional/System/AccessDeniedTest.php
AjaxCssTest::setUp in core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php
BookTest::testBookExport in core/modules/book/tests/src/Functional/BookTest.php
Tests book export ("printer-friendly version") functionality.
BreadcrumbTest::testBreadCrumbs in core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php
Tests breadcrumbs on node and administrative paths.
CommentAdminTest::testEditComment in core/modules/comment/tests/src/Functional/CommentAdminTest.php
Tests editing a comment as an admin.

... See full list

File

core/modules/user/user.module, line 990

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.