function CommentHooks::userPredelete

Implements hook_ENTITY_TYPE_predelete() for user entities.

Attributes

#[Hook('user_predelete')]

File

core/modules/comment/src/Hook/CommentHooks.php, line 434

Class

CommentHooks
Hook implementations for comment.

Namespace

Drupal\comment\Hook

Code

public function userPredelete($account) : void {
  $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.