Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CommentHooks.php

function CommentHooks::fieldConfigDelete

Implements hook_ENTITY_TYPE_delete() for 'field_config'.

File

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

Class

CommentHooks
Hook implementations for comment.

Namespace

Drupal\comment\Hook

Code

public function fieldConfigDelete(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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal