function RoleInterface::changePermissions
Same name and namespace in other branches
- 11.x core/modules/user/src/RoleInterface.php \Drupal\user\RoleInterface::changePermissions()
Changes permissions for a user role.
This method may be used to grant and revoke multiple permissions at once. For example, when a form exposes checkboxes to configure permissions for a role, the form submit handler may directly pass the submitted values for the checkboxes form element to this function.
Parameters
array $permissions: (optional) An associative array, where the key holds the permission name and the value determines whether to grant or revoke that permission. Any value that evaluates to TRUE will cause the permission to be granted. Any value that evaluates to FALSE will cause the permission to be revoked.
[
'administer nodes' => 0,
// Revoke 'administer nodes'
'administer blocks' => FALSE,
// Revoke 'administer blocks'
'access user profiles' => 1,
// Grant 'access user profiles'
'access content' => TRUE,
// Grant 'access content'
'access comments' => 'access comments',
];Existing permissions are not changed, unless specified in $permissions.
Return value
$this
See also
RoleInterface::grantPermissions()
RoleInterface::revokePermissions()
File
-
core/
modules/ user/ src/ RoleInterface.php, line 94
Class
- RoleInterface
- Provides an interface defining a user role entity.
Namespace
Drupal\userCode
public function changePermissions(array $permissions) : static;
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.