You are here

public function Role::calculateDependencies in Drupal 9

Same name in this branch
  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()
Same name and namespace in other branches
  1. 10 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::calculateDependencies()

Calculates dependencies and stores them in the dependency property.

Return value

$this

Overrides ConfigEntityBase::calculateDependencies

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

File

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

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;
}