public function Role::calculateDependencies in Drupal 10
Same name in this branch
- 10 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::calculateDependencies()
- 10 core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role::calculateDependencies()
Same name and namespace in other branches
- 9 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\EntityCode
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')) {
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;
}