diff --git a/core/modules/comment/migration_templates/d7_comment.yml b/core/modules/comment/migration_templates/d7_comment.yml index 94a2884477..5e609a6556 100644 --- a/core/modules/comment/migration_templates/d7_comment.yml +++ b/core/modules/comment/migration_templates/d7_comment.yml @@ -16,8 +16,15 @@ process: source: pid entity_id: nid entity_type: 'constants/entity_type' - comment_type: comment_type - field_name: comment_type + comment_type: + - + plugin: migration_lookup + source: comment_type + migration: d7_comment_type + - + plugin: skip_on_empty + method: row + field_name: '@comment_type' subject: subject uid: uid name: name diff --git a/core/modules/comment/migration_templates/d7_comment_entity_display.yml b/core/modules/comment/migration_templates/d7_comment_entity_display.yml index 2004505f3c..3ae948ecb3 100644 --- a/core/modules/comment/migration_templates/d7_comment_entity_display.yml +++ b/core/modules/comment/migration_templates/d7_comment_entity_display.yml @@ -13,7 +13,14 @@ source: weight: 20 process: entity_type: 'constants/entity_type' - field_name: bundle + field_name: + - + plugin: migration_lookup + source: bundle + migration: d7_comment_type + - + plugin: skip_on_empty + method: row view_mode: 'constants/view_mode' options: 'constants/options' bundle: node_type diff --git a/core/modules/comment/migration_templates/d7_comment_entity_form_display_subject.yml b/core/modules/comment/migration_templates/d7_comment_entity_form_display_subject.yml index c27303e876..46f231d0f8 100644 --- a/core/modules/comment/migration_templates/d7_comment_entity_form_display_subject.yml +++ b/core/modules/comment/migration_templates/d7_comment_entity_form_display_subject.yml @@ -22,7 +22,14 @@ process: map: 0: true 1: false - bundle: bundle + bundle: + - + plugin: migration_lookup + source: bundle + migration: d7_comment_type + - + plugin: skip_on_empty + method: row destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/comment/migration_templates/d7_comment_field.yml b/core/modules/comment/migration_templates/d7_comment_field.yml index b4b3543db1..95a4602349 100644 --- a/core/modules/comment/migration_templates/d7_comment_field.yml +++ b/core/modules/comment/migration_templates/d7_comment_field.yml @@ -9,9 +9,16 @@ source: type: comment process: entity_type: 'constants/entity_type' - field_name: bundle + field_name: + - + plugin: migration_lookup + source: bundle + migration: d7_comment_type + - + plugin: skip_on_empty + method: row type: 'constants/type' - 'settings/comment_type': bundle + 'settings/comment_type': '@field_name' destination: plugin: entity:field_storage_config migration_dependencies: diff --git a/core/modules/comment/migration_templates/d7_comment_field_instance.yml b/core/modules/comment/migration_templates/d7_comment_field_instance.yml index 80a1a5198c..147efcf25c 100644 --- a/core/modules/comment/migration_templates/d7_comment_field_instance.yml +++ b/core/modules/comment/migration_templates/d7_comment_field_instance.yml @@ -12,7 +12,14 @@ process: entity_type: 'constants/entity_type' label: 'constants/label' required: 'constants/required' - field_name: bundle + field_name: + - + plugin: migration_lookup + source: bundle + migration: d7_comment_type + - + plugin: skip_on_empty + method: row bundle: node_type 'default_value/0/status': 'constants/required' 'settings/default_mode': default_mode diff --git a/core/modules/comment/migration_templates/d7_comment_type.yml b/core/modules/comment/migration_templates/d7_comment_type.yml index 090bfdde29..38030a13bd 100644 --- a/core/modules/comment/migration_templates/d7_comment_type.yml +++ b/core/modules/comment/migration_templates/d7_comment_type.yml @@ -8,7 +8,22 @@ source: entity_type: node process: target_entity_type_id: 'constants/entity_type' - id: bundle + id: + plugin: static_map + source: bundle + bypass: true + # If the destination site installed the Standard profile, there will + # already be a 'comment' comment type, and the Article node type will be + # using it. To avoid data integrity issues, we want to reuse that comment + # type and the associated field. If the destination site did NOT install + # Standard, this will create the 'comment' comment type. The Forum module, + # meanwhile, also provides its own comment type (comment_forum), which we + # want to reuse if it exists, for the same reason that we want to reuse + # the 'comment' comment type if it exists. + # See https://www.drupal.org/node/2853872 for more information. + map: + comment_node_article: comment + comment_node_forum: comment_forum label: label destination: plugin: entity:comment_type diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php index 871765b834..b64ed72ec3 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php @@ -50,10 +50,10 @@ protected function assertDisplay($id, $component_id) { */ public function testMigration() { $this->assertDisplay('node.page.default', 'comment_node_page'); - $this->assertDisplay('node.article.default', 'comment_node_article'); + $this->assertDisplay('node.article.default', 'comment'); $this->assertDisplay('node.book.default', 'comment_node_book'); $this->assertDisplay('node.blog.default', 'comment_node_blog'); - $this->assertDisplay('node.forum.default', 'comment_node_forum'); + $this->assertDisplay('node.forum.default', 'comment_forum'); $this->assertDisplay('node.test_content_type.default', 'comment_node_test_content_type'); } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php index 8ce439a9cf..5c9e63c8b8 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php @@ -45,10 +45,10 @@ protected function assertDisplay($id) { */ public function testMigration() { $this->assertDisplay('comment.comment_node_page.default'); - $this->assertDisplay('comment.comment_node_article.default'); + $this->assertDisplay('comment.comment.default'); $this->assertDisplay('comment.comment_node_book.default'); $this->assertDisplay('comment.comment_node_blog.default'); - $this->assertDisplay('comment.comment_node_forum.default'); + $this->assertDisplay('comment.comment_forum.default'); $this->assertDisplay('comment.comment_node_test_content_type.default'); } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php index cc82c82766..7172daca69 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php @@ -76,10 +76,10 @@ protected function assertEntity($id, $field_name, $bundle, $default_mode, $per_p */ public function testMigration() { $this->assertEntity('node.page.comment_node_page', 'comment_node_page', 'page', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); - $this->assertEntity('node.article.comment_node_article', 'comment_node_article', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); + $this->assertEntity('node.article.comment', 'comment', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); $this->assertEntity('node.blog.comment_node_blog', 'comment_node_blog', 'blog', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); $this->assertEntity('node.book.comment_node_book', 'comment_node_book', 'book', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); - $this->assertEntity('node.forum.comment_node_forum', 'comment_node_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); + $this->assertEntity('node.forum.comment_forum', 'comment_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); $this->assertEntity('node.test_content_type.comment_node_test_content_type', 'comment_node_test_content_type', 'test_content_type', TRUE, 30, FALSE, CommentItemInterface::FORM_BELOW, TRUE); } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php index b995bdb0a5..1596aece5b 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php @@ -51,10 +51,10 @@ protected function assertEntity($id, $comment_type) { */ public function testMigration() { $this->assertEntity('node.comment_node_page', 'comment_node_page'); - $this->assertEntity('node.comment_node_article', 'comment_node_article'); + $this->assertEntity('node.comment', 'comment'); $this->assertEntity('node.comment_node_blog', 'comment_node_blog'); $this->assertEntity('node.comment_node_book', 'comment_node_book'); - $this->assertEntity('node.comment_node_forum', 'comment_node_forum'); + $this->assertEntity('node.comment_forum', 'comment_forum'); $this->assertEntity('node.comment_node_test_content_type', 'comment_node_test_content_type'); } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php index 60f640d297..f9996f6f98 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php @@ -48,10 +48,10 @@ protected function assertEntity($id, $label) { */ public function testMigration() { $this->assertEntity('comment_node_page', 'Basic page comment'); - $this->assertEntity('comment_node_article', 'Article comment'); + $this->assertEntity('comment', 'Article comment'); $this->assertEntity('comment_node_blog', 'Blog entry comment'); $this->assertEntity('comment_node_book', 'Book page comment'); - $this->assertEntity('comment_node_forum', 'Forum topic comment'); + $this->assertEntity('comment_forum', 'Forum topic comment'); $this->assertEntity('comment_node_test_content_type', 'Test content type comment'); $migration = $this->getMigration('d7_comment_type'); diff --git a/core/modules/field/migration_templates/d7_field_formatter_settings.yml b/core/modules/field/migration_templates/d7_field_formatter_settings.yml index 126fd29a20..2c2ec93d42 100644 --- a/core/modules/field/migration_templates/d7_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d7_field_formatter_settings.yml @@ -26,7 +26,17 @@ process: plugin: skip_on_empty method: row entity_type: entity_type - bundle: bundle + # The bundle needs to be statically mapped in order to support comment types + # that might already exist before this migration is run. See + # core/modules/comment/migration_templates/d7_comment_type.yml and + # https://www.drupal.org/node/2853872 for more information. + bundle: + plugin: static_map + source: bundle + bypass: true + map: + comment_node_article: comment + comment_node_forum: comment_forum view_mode: - plugin: migration_lookup diff --git a/core/modules/field/migration_templates/d7_field_instance.yml b/core/modules/field/migration_templates/d7_field_instance.yml index f3518c91a2..d0f7504e86 100644 --- a/core/modules/field/migration_templates/d7_field_instance.yml +++ b/core/modules/field/migration_templates/d7_field_instance.yml @@ -11,7 +11,17 @@ source: process: entity_type: entity_type field_name: field_name - bundle: bundle + # The bundle needs to be statically mapped in order to support comment types + # that might already exist before this migration is run. See + # core/modules/comment/migration_templates/d7_comment_type.yml and + # https://www.drupal.org/node/2853872 for more information. + bundle: + plugin: static_map + source: bundle + bypass: true + map: + comment_node_article: comment + comment_node_forum: comment_forum label: label description: description required: required diff --git a/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml b/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml index e2bbcf4496..9202d4f099 100644 --- a/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml +++ b/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml @@ -26,7 +26,17 @@ process: - plugin: skip_on_empty method: row - bundle: bundle + # The bundle needs to be statically mapped in order to support comment types + # that might already exist before this migration is run. See + # core/modules/comment/migration_templates/d7_comment_type.yml and + # https://www.drupal.org/node/2853872 for more information. + bundle: + plugin: static_map + source: bundle + bypass: true + map: + comment_node_article: comment + comment_node_forum: comment_forum form_mode: 'constants/form_mode' field_name: field_name entity_type: entity_type diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php index dd38569de1..8ba7c3b29d 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php @@ -44,7 +44,7 @@ protected function setUp() { 'label' => $this->randomMachineName(), ])->save(); CommentType::create([ - 'id' => 'comment_node_article', + 'id' => 'comment', 'label' => $this->randomMachineName(), ])->save(); CommentType::create([ @@ -56,7 +56,7 @@ protected function setUp() { 'label' => $this->randomMachineName(), ])->save(); CommentType::create([ - 'id' => 'comment_node_forum', + 'id' => 'comment_forum', 'label' => $this->randomMachineName(), ])->save(); CommentType::create([ @@ -206,8 +206,8 @@ protected function assertComponentNotExists($display_id, $component_id) { * Tests migration of D7 field formatter settings. */ public function testMigration() { - $this->assertEntity('comment.comment_node_article.default'); - $this->assertComponent('comment.comment_node_article.default', 'comment_body', 'text_default', 'hidden', 0); + $this->assertEntity('comment.comment.default'); + $this->assertComponent('comment.comment.default', 'comment_body', 'text_default', 'hidden', 0); $this->assertEntity('comment.comment_node_blog.default'); $this->assertComponent('comment.comment_node_blog.default', 'comment_body', 'text_default', 'hidden', 0); @@ -215,8 +215,8 @@ public function testMigration() { $this->assertEntity('comment.comment_node_book.default'); $this->assertComponent('comment.comment_node_book.default', 'comment_body', 'text_default', 'hidden', 0); - $this->assertEntity('comment.comment_node_forum.default'); - $this->assertComponent('comment.comment_node_forum.default', 'comment_body', 'text_default', 'hidden', 0); + $this->assertEntity('comment.comment_forum.default'); + $this->assertComponent('comment.comment_forum.default', 'comment_body', 'text_default', 'hidden', 0); $this->assertEntity('comment.comment_node_page.default'); $this->assertComponent('comment.comment_node_page.default', 'comment_body', 'text_default', 'hidden', 0); diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php index 1e3df9e4fc..801961bbeb 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php @@ -17,9 +17,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase { /** - * The modules to be enabled during the test. - * - * @var array + * {@inheritdoc} */ public static $modules = [ 'comment', @@ -40,12 +38,12 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase { protected function setUp() { parent::setUp(); $this->installConfig(static::$modules); - $this->createType('page'); - $this->createType('article'); - $this->createType('blog'); - $this->createType('book'); - $this->createType('forum'); - $this->createType('test_content_type'); + $this->createType('page', 'comment_node_page'); + $this->createType('article', 'comment'); + $this->createType('blog', 'comment_node_blog'); + $this->createType('book', 'comment_node_book'); + $this->createType('forum', 'comment_forum'); + $this->createType('test_content_type', 'comment_node_test_content_type'); Vocabulary::create(['vid' => 'test_vocabulary'])->save(); $this->executeMigrations(['d7_field', 'd7_field_instance']); } @@ -53,17 +51,19 @@ protected function setUp() { /** * Creates a node type with a corresponding comment type. * - * @param string $id + * @param string $node_type * The node type ID. + * @param string $comment_type + * The ID of the comment type. */ - protected function createType($id) { + protected function createType($node_type, $comment_type) { NodeType::create([ - 'type' => $id, + 'type' => $node_type, 'label' => $this->randomString(), ])->save(); CommentType::create([ - 'id' => 'comment_node_' . $id, + 'id' => $comment_type, 'label' => $this->randomString(), 'target_entity_type_id' => 'node', ])->save(); @@ -118,7 +118,7 @@ protected function assertLinkFields($id, $title_setting) { public function testFieldInstances() { $this->assertEntity('comment.comment_node_page.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('node.page.body', 'Body', 'text_with_summary', FALSE, FALSE); - $this->assertEntity('comment.comment_node_article.comment_body', 'Comment', 'text_long', TRUE, FALSE); + $this->assertEntity('comment.comment.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('node.article.body', 'Body', 'text_with_summary', FALSE, TRUE); $this->assertEntity('node.article.field_tags', 'Tags', 'entity_reference', FALSE, TRUE); $this->assertEntity('node.article.field_image', 'Image', 'image', FALSE, TRUE); @@ -127,7 +127,7 @@ public function testFieldInstances() { $this->assertEntity('comment.comment_node_book.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('node.book.body', 'Body', 'text_with_summary', FALSE, FALSE); $this->assertEntity('node.forum.taxonomy_forums', 'Forums', 'entity_reference', TRUE, FALSE); - $this->assertEntity('comment.comment_node_forum.comment_body', 'Comment', 'text_long', TRUE, FALSE); + $this->assertEntity('comment.comment_forum.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('node.forum.body', 'Body', 'text_with_summary', FALSE, FALSE); $this->assertEntity('comment.comment_node_test_content_type.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('node.test_content_type.field_boolean', 'Boolean', 'boolean', FALSE, FALSE); diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackFieldInstanceTest.php index e71ac3ce95..90c62cbb50 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackFieldInstanceTest.php @@ -26,7 +26,7 @@ public function testFieldInstances() { $field_instance_ids = [ 'comment.comment_node_page.comment_body', 'node.page.body', - 'comment.comment_node_article.comment_body', + 'comment.comment.comment_body', 'node.article.body', 'node.article.field_tags', 'node.article.field_image', @@ -35,7 +35,7 @@ public function testFieldInstances() { 'comment.comment_node_book.comment_body', 'node.book.body', 'node.forum.taxonomy_forums', - 'comment.comment_node_forum.comment_body', + 'comment.comment_forum.comment_body', 'node.forum.body', 'comment.comment_node_test_content_type.comment_body', 'node.test_content_type.field_boolean', diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php index 6bb46a9fec..f9cdc40b9c 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php @@ -40,13 +40,13 @@ protected function getEntityCounts() { 'block_content' => 1, 'block_content_type' => 1, 'comment' => 1, - 'comment_type' => 8, + 'comment_type' => 6, // Module 'language' comes with 'en', 'und', 'zxx'. Migration adds 'is'. 'configurable_language' => 4, 'contact_form' => 3, 'editor' => 2, - 'field_config' => 52, - 'field_storage_config' => 39, + 'field_config' => 48, + 'field_storage_config' => 37, 'file' => 2, 'filter_format' => 7, 'image_style' => 6, @@ -68,9 +68,9 @@ protected function getEntityCounts() { 'menu_link_content' => 7, 'view' => 14, 'date_format' => 11, - 'entity_form_display' => 18, + 'entity_form_display' => 16, 'entity_form_mode' => 1, - 'entity_view_display' => 29, + 'entity_view_display' => 27, 'entity_view_mode' => 14, 'base_field_override' => 9, ]; diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php index 7d73dafecd..e3202b32ef 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php @@ -43,12 +43,12 @@ protected function setUp() { // Prepare to migrate user pictures as well. $this->installEntitySchema('file'); - $this->createType('page'); - $this->createType('article'); - $this->createType('blog'); - $this->createType('book'); - $this->createType('forum'); - $this->createType('test_content_type'); + $this->createType('page', 'comment_node_page'); + $this->createType('article', 'comment'); + $this->createType('blog', 'comment_node_blog'); + $this->createType('book', 'comment_node_book'); + $this->createType('forum', 'comment_forum'); + $this->createType('test_content_type', 'comment_node_test_content_type'); Vocabulary::create(['vid' => 'test_vocabulary'])->save(); $this->executeMigrations([ 'language', @@ -64,17 +64,19 @@ protected function setUp() { /** * Creates a node type with a corresponding comment type. * - * @param string $id + * @param string $node_type * The node type ID. + * @param string $comment_type + * The comment type ID. */ - protected function createType($id) { + protected function createType($node_type, $comment_type) { NodeType::create([ - 'type' => $id, + 'type' => $node_type, 'label' => $this->randomString(), ])->save(); CommentType::create([ - 'id' => 'comment_node_' . $id, + 'id' => $comment_type, 'label' => $this->randomString(), 'target_entity_type_id' => 'node', ])->save();