function user_role_grant_permissions in Drupal 8
Same name and namespace in other branches
- 7 modules/user/user.module \user_role_grant_permissions()
- 9 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()
33 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.
File
- core/
modules/ user/ user.module, line 1228 - Enables the user registration and login system.
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();
}
}