diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index c5b8141ff07..503e32a31e9 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -218,22 +218,34 @@ function comment_count_unpublished() { return t('Unapproved comments (@count)', array('@count' => $count)); } +/** + * Implements hook_ENTITY_TYPE_insert() for 'field_instance'. + */ +function comment_field_instance_insert(FieldInstanceInterface $instance) { + if ($instance->getType() == 'comment' && !$instance->isSyncing()) { + \Drupal::service('comment.manager')->addBodyField($instance->entity_type, $instance->getName()); + \Drupal::cache()->delete('comment_entity_info'); + } +} + /** * Implements hook_ENTITY_TYPE_create() for 'field_instance'. */ function comment_field_instance_create(FieldInstanceInterface $instance) { if ($instance->getType() == 'comment' && !$instance->isSyncing()) { - \Drupal::service('comment.manager')->addBodyField($instance->entity_type, $instance->getName()); - \Drupal::cache()->delete('comment_entity_info'); // Assign default values for the field instance. - $instance->default_value = array(array( + if (!isset($instance->default_value)) { + $instance->default_value = array(); + } + $instance->default_value += array(array()); + $instance->default_value[0] += array( 'status' => COMMENT_OPEN, 'cid' => 0, 'last_comment_timestamp' => 0, 'last_comment_name' => '', 'last_comment_uid' => 0, 'comment_count' => 0, - )); + ); } } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php index 0e697395548..c0b2aaf9487 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php @@ -57,6 +57,11 @@ class CommentFieldsTest extends CommentTestBase { $this->assertTrue($field, 'The comment_body field exists'); $instances = $this->container->get('field.info')->getInstances('comment'); $this->assertTrue(isset($instances['node__comment']['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name))); + + // Test adding a field that defaults to COMMENT_CLOSED. + $this->container->get('comment.manager')->addDefaultField('node', 'test_node_type', 'who_likes_ponies', COMMENT_CLOSED); + $field = entity_load('field_instance', 'node.test_node_type.who_likes_ponies'); + $this->assertEqual($field->default_value[0]['status'], COMMENT_CLOSED); } /** diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc index 95af3a72f0b..cd8cd04b968 100644 --- a/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -85,12 +85,6 @@ function field_purge_batch($batch_size) { continue; } - // EntityFieldQuery currently fails on conditions on comment bundle. - // Remove when http://drupal.org/node/731724 is fixed. - if ($entity_type == 'comment') { - continue; - } - $ids = (object) array( 'entity_type' => $entity_type, 'bundle' => $instance->bundle,