function Role::onDependencyRemoval
Same name in other branches
- 9 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::onDependencyRemoval()
- 10 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::onDependencyRemoval()
Overrides ConfigEntityBase::onDependencyRemoval
File
-
core/
modules/ user/ src/ Entity/ Role.php, line 226
Class
- Role
- Defines the user role entity class.
Namespace
Drupal\user\EntityCode
public function onDependencyRemoval(array $dependencies) {
$changed = parent::onDependencyRemoval($dependencies);
// Load all permission definitions.
$permission_definitions = \Drupal::service('user.permissions')->getPermissions();
// Convert config and content entity dependencies to a list of names to make
// it easier to check.
foreach ([
'content',
'config',
] as $type) {
$dependencies[$type] = array_keys($dependencies[$type]);
}
// Remove any permissions from the role that are dependent on anything being
// deleted or uninstalled.
foreach ($this->permissions as $key => $permission) {
if (!isset($permission_definitions[$permission])) {
// If the permission is not defined then there's nothing we can do.
continue;
}
if (in_array($permission_definitions[$permission]['provider'], $dependencies['module'], TRUE)) {
unset($this->permissions[$key]);
$changed = TRUE;
// Process the next permission.
continue;
}
if (isset($permission_definitions[$permission]['dependencies'])) {
foreach ($permission_definitions[$permission]['dependencies'] as $type => $list) {
if (array_intersect($list, $dependencies[$type])) {
unset($this->permissions[$key]);
$changed = TRUE;
// Process the next permission.
continue 2;
}
}
}
}
return $changed;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.