Issue #2172123 by larowlan, chx, andypost: Fix various issues with comment_field_instance_create().
parent
42e2c36937
commit
854c8661ba
|
@ -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,
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue