function role_delegation_user_role_delete in Role Delegation 8
Same name and namespace in other branches
- 7 role_delegation.module \role_delegation_user_role_delete()
Implements hook_ENTITY_TYPE_delete().
File
- ./
role_delegation.module, line 45 - Allows admins to grant roles the authority to assign selected roles to users.
Code
function role_delegation_user_role_delete(RoleInterface $entity) {
$permission = sprintf('assign %s role', $entity
->id());
/** @var array $roles */
$roles = \Drupal::entityQuery('user_role')
->condition('permissions.*', $permission)
->condition('id', $entity
->id(), '<>')
->execute();
/** @var \Drupal\user\RoleInterface $role */
foreach (Role::loadMultiple($roles) as $role) {
$role
->revokePermission($permission);
$role
->save();
}
}