function Role::calculateDependencies

Same name in this branch
  1. 11.x core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role::calculateDependencies()
Same name in other branches
  1. 9 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::calculateDependencies()
  2. 9 core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role::calculateDependencies()
  3. 8.9.x core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role::calculateDependencies()
  4. 10 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::calculateDependencies()
  5. 10 core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role::calculateDependencies()

Overrides ConfigEntityBase::calculateDependencies

File

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

Class

Role
Defines the user role entity class.

Namespace

Drupal\user\Entity

Code

public function calculateDependencies() {
    parent::calculateDependencies();
    // Load all permission definitions.
    $permission_definitions = \Drupal::service('user.permissions')->getPermissions();
    $valid_permissions = array_intersect($this->permissions, array_keys($permission_definitions));
    $invalid_permissions = array_diff($this->permissions, $valid_permissions);
    if (!empty($invalid_permissions)) {
        throw new \RuntimeException('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "' . implode('", "', $invalid_permissions) . '".');
    }
    foreach ($valid_permissions as $permission) {
        // Depend on the module that is providing this permissions.
        $this->addDependency('module', $permission_definitions[$permission]['provider']);
        // Depend on any other dependencies defined by permissions granted to
        // this role.
        if (!empty($permission_definitions[$permission]['dependencies'])) {
            $this->addDependencies($permission_definitions[$permission]['dependencies']);
        }
    }
    return $this;
}

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