function Role::calculateDependencies

Same name in this branch
  1. 9 core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role::calculateDependencies()
Same name in other branches
  1. 8.9.x core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role::calculateDependencies()
  2. 10 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::calculateDependencies()
  3. 10 core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role::calculateDependencies()
  4. 11.x core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::calculateDependencies()
  5. 11.x 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 200

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) && !$this->get('skip_missing_permission_deprecation')) {
        @trigger_error('Adding non-existent permissions to a role is deprecated in drupal:9.3.0 and triggers a runtime exception before drupal:10.0.0. The incorrect permissions are "' . implode('", "', $invalid_permissions) . '". Permissions should be defined in a permissions.yml file or a permission callback. See https://www.drupal.org/node/3193348', E_USER_DEPRECATED);
    }
    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.