function user_role_grant_permissions

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

35 calls to user_role_grant_permissions()
AccessDeniedTest::setUp in core/modules/system/tests/src/Functional/System/AccessDeniedTest.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.
CommentAnonymousTest::setUp in core/modules/comment/tests/src/Functional/CommentAnonymousTest.php

... See full list

File

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

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.