diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 0e5c0cfaa6..ad92f09e73 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -203,8 +203,11 @@ function comment_field_config_delete(FieldConfigInterface $field) { // - Delete comments only from the bundle the field was deleted from. $entity_type = \Drupal::entityTypeManager()->getDefinition($field->getTargetEntityTypeId()); $bundle_field = $entity_type->getKey('bundle'); + $comment_query = \Drupal::entityQuery('comment'); - $comment_query->condition('field_name', $field->getName()); + $comment_query + ->condition('entity_type', $field->getTargetEntityTypeId()) + ->condition('field_name', $field->getName()); if ($bundle_field) { $key = 'entity_id.entity.' . $bundle_field; $comment_query->condition($key, $field->getTargetBundle()); @@ -215,19 +218,17 @@ function comment_field_config_delete(FieldConfigInterface $field) { // Delete the comment statistics for this comment field. // Deletions need to be limited by the bundle the same way as above. // Get a list of entity_ids that are affected by the field deletion. - $entity_query = \Drupal::entityQuery($field->getTargetEntityTypeId()); + $connection = \Drupal::database(); + $entity_query = $connection->select($entity_type->getBaseTable(), 'base_table'); + $entity_query->addField('base_table', $entity_type->getKey('id')); if ($bundle_field) { $entity_query->condition($bundle_field, $field->getTargetBundle()); } - $entity_ids = $entity_query->execute(); - // Delete the comment statistics. - if (!empty($entity_ids)) { - \Drupal::database()->delete('comment_entity_statistics') - ->condition('entity_type', $field->getTargetEntityTypeId()) - ->condition('field_name', $field->getName()) - ->condition('entity_id', $entity_ids, 'IN') - ->execute(); - } + $connection->delete('comment_entity_statistics') + ->condition('entity_type', $field->getTargetEntityTypeId()) + ->condition('field_name', $field->getName()) + ->condition('entity_id', $entity_query, 'IN') + ->execute(); } }