function Role::grantPermissions
Same name and namespace in other branches
- 11.x core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::grantPermissions()
Grants permissions to the role.
Parameters
array $permissions: The permissions to grant.
Return value
$this
Overrides RoleInterface::grantPermissions
2 calls to Role::grantPermissions()
- Role::changePermissions in core/
modules/ user/ src/ Entity/ Role.php - Changes permissions for a user role.
- Role::grantPermission in core/
modules/ user/ src/ Entity/ Role.php - #[ActionMethod(adminLabel: new TranslatableMarkup('Add permission to role'))]
File
-
core/
modules/ user/ src/ Entity/ Role.php, line 144
Class
- Role
- Defines the user role entity class.
Namespace
Drupal\user\EntityCode
public function grantPermissions(array $permissions) : static {
if ($this->isAdmin()) {
return $this;
}
// Remove existing permissions.
$permissions = array_diff($permissions, $this->permissions);
$this->permissions = array_merge($this->permissions, $permissions);
return $this;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.