function userprotect_user_delete in User protect 8
Same name and namespace in other branches
- 7 userprotect.module \userprotect_user_delete()
Implements hook_user_delete().
When an user is deleted, delete all associated protection rules as well.
File
- ./
userprotect.module, line 173 - Allows admins to protect users from being edited or cancelled.
Code
function userprotect_user_delete($account) {
// Lookup all protection rules for this user.
$entity_ids = \Drupal::entityQuery('userprotect_rule')
->condition('protectedEntityTypeId', 'user')
->condition('protectedEntityId', $account
->id())
->execute();
// Delete protection rules.
if (!empty($entity_ids)) {
$storage_handler = \Drupal::entityTypeManager()
->getStorage('userprotect_rule');
$entities = $storage_handler
->loadMultiple($entity_ids);
$storage_handler
->delete($entities);
}
}