Same name and namespace in other branches
  1. 8.9.x core/modules/comment/comment.module \comment_user_predelete()
  2. 9 core/modules/comment/comment.module \comment_user_predelete()

Implements hook_ENTITY_TYPE_predelete() for user entities.

File

core/modules/comment/comment.module, line 485
Enables users to comment on published content.

Code

function comment_user_predelete($account) {
  $entity_query = \Drupal::entityQuery('comment')
    ->accessCheck(FALSE);
  $entity_query
    ->condition('uid', $account
    ->id());
  $cids = $entity_query
    ->execute();
  $comment_storage = \Drupal::entityTypeManager()
    ->getStorage('comment');
  $comments = $comment_storage
    ->loadMultiple($cids);
  $comment_storage
    ->delete($comments);
}