You are here

function comment_field_config_delete in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/comment/comment.module \comment_field_config_delete()
  2. 9 core/modules/comment/comment.module \comment_field_config_delete()

Implements hook_ENTITY_TYPE_delete() for 'field_config'.

File

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

Code

function comment_field_config_delete(FieldConfigInterface $field) {
  if ($field
    ->getType() == 'comment') {

    // Delete all comments that used by the entity bundle.
    $entity_query = \Drupal::entityQuery('comment')
      ->accessCheck(FALSE);
    $entity_query
      ->condition('entity_type', $field
      ->getEntityTypeId());
    $entity_query
      ->condition('field_name', $field
      ->getName());
    $cids = $entity_query
      ->execute();
    $comment_storage = \Drupal::entityTypeManager()
      ->getStorage('comment');
    $comments = $comment_storage
      ->loadMultiple($cids);
    $comment_storage
      ->delete($comments);
  }
}