function Role::changePermissions

Same name and namespace in other branches
  1. main core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::changePermissions()

File

core/modules/user/src/Entity/Role.php, line 157

Class

Role
Defines the user role entity class.

Namespace

Drupal\user\Entity

Code

public function changePermissions(array $permissions) : static {
  // Grant new permissions for the role.
  $grant = array_filter($permissions);
  if (!empty($grant)) {
    $this->grantPermissions(array_keys($grant));
  }
  // Revoke permissions for the role.
  $revoke = array_diff_assoc($permissions, $grant);
  if (!empty($revoke)) {
    $this->revokePermissions(array_keys($revoke));
  }
  return $this;
}

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