function opigno_notification_user_delete in Opigno notifications 8
Same name and namespace in other branches
- 3.x opigno_notification.module \opigno_notification_user_delete()
Removes notifications for deleted user.
Implements hook_user_delete().
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- ./
opigno_notification.module, line 62 - Contains opigno_notification.module.
Code
function opigno_notification_user_delete(EntityInterface $entity) {
/** @var \Drupal\opigno_notification\OpignoNotificationInterface[] $list */
$list = \Drupal::entityTypeManager()
->getStorage('opigno_notification')
->loadByProperties([
'uid' => $entity
->id(),
]);
if ($list) {
foreach ($list as $notification) {
try {
$notification
->delete();
} catch (\Exception $e) {
\Drupal::logger('opigno_notification')
->error($e
->getMessage());
\Drupal::messenger()
->addMessage($e
->getMessage(), 'error');
}
}
}
}