diff --git a/core/modules/comment/config/schema/comment.schema.yml b/core/modules/comment/config/schema/comment.schema.yml index 568ca1d..d4c9e53 100644 --- a/core/modules/comment/config/schema/comment.schema.yml +++ b/core/modules/comment/config/schema/comment.schema.yml @@ -68,3 +68,6 @@ comment.type.*: langcode: type: string label: 'Default language' + dependencies: + type: config_dependencies + label: 'Dependencies' diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index cbe33a2..0a976d9 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -139,7 +139,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $field->save(); } // Make sure the instance doesn't already exist. - if (!$this->entityManager->getStorage('field_instance_config')->load($entity_type . '.' . $bundle . '.' . $field_name)) { + if (!array_key_exists($field_name, $this->entityManager->getFieldDefinitions($entity_type, $bundle))) { $instance = $this->entityManager->getStorage('field_instance_config')->create(array( 'label' => 'Comment settings', 'description' => '', @@ -201,7 +201,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', */ public function addBodyField($comment_type_id) { // Create the field if needed. - $field = $this->entityManager->getStorage('field_config')->load('comment.comment_body'); + $field = FieldConfig::loadByName('comment', 'comment_body'); if (!$field) { $field = $this->entityManager->getStorage('field_config')->create(array( 'name' => 'comment_body', @@ -210,10 +210,9 @@ public function addBodyField($comment_type_id) { )); $field->save(); } - $field_instance = $this->entityManager - ->getStorage('field_instance_config') - ->load("comment.$comment_type_id.comment_body"); - if (!$field_instance) { + $field_instances = $this->entityManager + ->getFieldDefinitions('comment', $comment_type_id); + if (empty($field_instances['comment_body'])) { // Attaches the body field by default. $field_instance = $this->entityManager->getStorage('field_instance_config')->create(array( 'field_name' => 'comment_body', @@ -240,6 +239,8 @@ public function addBodyField($comment_type_id) { 'weight' => 0, )) ->save(); + + $this->entityManager->clearCachedFieldDefinitions(); } } diff --git a/core/modules/comment/lib/Drupal/comment/Form/CommentTypeDeleteForm.php b/core/modules/comment/lib/Drupal/comment/Form/CommentTypeDeleteForm.php index 9775892..d44dba6 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/CommentTypeDeleteForm.php +++ b/core/modules/comment/lib/Drupal/comment/Form/CommentTypeDeleteForm.php @@ -114,7 +114,7 @@ public function buildForm(array $form, array &$form_state) { } if (!empty($comments)) { - $caption .= '

' . $this->translationManager()->formatPlural(count($comments), '%label is used by 1 comment on your site. You can not remove this comment type until you have removed all of the %label comments.', '%label is used by @count comments on your site. You may not remove %label until you have removed all of the %label comments.', array('%label' => $this->entity->label())) . '

'; + $caption .= '

' . $this->formatPlural(count($comments), '%label is used by 1 comment on your site. You can not remove this comment type until you have removed all of the %label comments.', '%label is used by @count comments on your site. You may not remove %label until you have removed all of the %label comments.', array('%label' => $this->entity->label())) . '

'; } if ($caption) { $form['description'] = array('#markup' => $caption); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentDefaultFormatterCacheTagsTest.php index 3fe2a3f..7fb615a 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentDefaultFormatterCacheTagsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentDefaultFormatterCacheTagsTest.php @@ -56,25 +56,7 @@ public function setUp() { // Set up a field, so that the entity that'll be referenced bubbles up a // cache tag when rendering it entirely. - entity_create('field_config', array( - 'name' => 'comment', - 'entity_type' => 'entity_test', - 'type' => 'comment', - 'settings' => array(), - ))->save(); - entity_create('field_instance_config', array( - 'entity_type' => 'entity_test', - 'bundle' => 'entity_test', - 'field_name' => 'comment', - 'label' => 'Comment', - 'settings' => array(), - ))->save(); - entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent('comment', array( - 'type' => 'comment_default', - 'settings' => array(), - )) - ->save(); + \Drupal::service('comment.manager')->addDefaultField('entity_test', 'entity_test'); } /** @@ -109,6 +91,7 @@ public function testCacheTags() { 'entity_id' => $commented_entity->id(), 'entity_type' => 'entity_test', 'field_name' => 'comment', + 'comment_type' => 'comment', 'status' => CommentInterface::PUBLISHED, 'uid' => $user->id(), )); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php index 4319081..d3c2ccd 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php @@ -39,12 +39,18 @@ function setUp() { // Create a bundle for entity_test. entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test'); + entity_create('comment_type', array( + 'id' => 'comment', + 'label' => 'Comment settings', + 'description' => 'Comment settings', + 'targetEntityTypeId' => 'entity_test', + ))->save(); // Create comment field on entity_test bundle. $this->container->get('comment.manager')->addDefaultField('entity_test', 'entity_test'); // Verify that bundles are defined correctly. $bundles = \Drupal::entityManager()->getBundleInfo('comment'); - $this->assertEqual($bundles['entity_test__comment']['label'], 'Comment settings'); + $this->assertEqual($bundles['comment']['label'], 'Comment settings'); // Create test user. $this->admin_user = $this->drupalCreateUser(array( diff --git a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityComment.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityComment.php index 42d3723..7066970 100644 --- a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityComment.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityComment.php @@ -80,6 +80,8 @@ public static function create(ContainerInterface $container, array $configuratio public function import(Row $row, array $old_destination_id_values = array()) { if (($stub = !$row->getSourceProperty('entity_type')) && ($state = $this->state->get('comment.maintain_entity_statistics', 0))) { $this->state->set('comment.maintain_entity_statistics', 0); + // Set default bundle. + $row->setDestinationProperty('comment_type', 'comment'); } $return = parent::import($row, $old_destination_id_values); if ($stub && $state) { diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field.yml index 5c4dd3b..2a5ccc4 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field.yml @@ -7,10 +7,13 @@ source: type: comment id: node.comment name: comment + settings: + content_type: comment process: entity_type: constants.entity_type id: constants.id name: constants.name type: constants.type + settings: constants.settings destination: plugin: entity:field_config diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php index 409f6d2..ffc3752 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php @@ -37,6 +37,12 @@ public static function getInfo() { public function setUp() { parent::setUp(); entity_create('node_type', array('type' => 'page'))->save(); + $this->container->get('entity.manager')->getStorage('comment_type')->create(array( + 'id' => 'comment', + 'label' => 'comment', + 'targetEntityTypeId' => 'node', + ))->save(); + $node = entity_create('node', array( 'type' => 'page', 'nid' => 1,