diff --git a/core/modules/comment/migration_templates/d6_comment_entity_display.yml b/core/modules/comment/migration_templates/d6_comment_entity_display.yml index c650673188..89e159c47c 100644 --- a/core/modules/comment/migration_templates/d6_comment_entity_display.yml +++ b/core/modules/comment/migration_templates/d6_comment_entity_display.yml @@ -3,10 +3,9 @@ label: Comment display configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable + plugin: d6_node_type constants: entity_type: node - field_name: comment view_mode: default options: label: hidden @@ -14,10 +13,17 @@ source: weight: 20 process: entity_type: 'constants/entity_type' - field_name: 'constants/field_name' + field_name: + - + plugin: migration_lookup + source: type + migration: d6_comment_type + - + plugin: skip_on_empty + method: row view_mode: 'constants/view_mode' options: 'constants/options' - bundle: node_type + bundle: type destination: plugin: component_entity_display migration_dependencies: diff --git a/core/modules/comment/migration_templates/d6_comment_entity_form_display.yml b/core/modules/comment/migration_templates/d6_comment_entity_form_display.yml index c33685feb6..274f3de96d 100644 --- a/core/modules/comment/migration_templates/d6_comment_entity_form_display.yml +++ b/core/modules/comment/migration_templates/d6_comment_entity_form_display.yml @@ -3,20 +3,26 @@ label: Comment field form display configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable + plugin: d6_node_type constants: entity_type: node - field_name: comment form_mode: default options: type: comment_default weight: 20 process: entity_type: 'constants/entity_type' - field_name: 'constants/field_name' + field_name: + - + plugin: migration_lookup + source: type + migration: d6_comment_type + - + plugin: skip_on_empty + method: row form_mode: 'constants/form_mode' options: 'constants/options' - bundle: node_type + bundle: type destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml b/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml index abe6191b8c..8c293ff831 100644 --- a/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml +++ b/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml @@ -3,7 +3,7 @@ label: Comment subject form display configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable_per_comment_type + plugin: d6_node_type constants: entity_type: comment field_name: subject @@ -16,14 +16,23 @@ process: field_name: 'constants/field_name' form_mode: 'constants/form_mode' options: 'constants/options' + bundle: + - + plugin: migration_lookup + source: type + migration: d6_comment_type + - + plugin: skip_on_empty + method: row hidden: plugin: static_map - source: comment_type - default_value: false + source: comment_subject_field + bypass: true map: - comment_no_subject: true # Hide subject field - comment: false - bundle: comment_type + # If comment_subject_field = FALSE, then hidden = TRUE. + 0: true + # If comment_subject_field = TRUE, then hidden = FALSE. + 1: false destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/comment/migration_templates/d6_comment_field.yml b/core/modules/comment/migration_templates/d6_comment_field.yml index d14d1aa4fc..b9a5dea132 100644 --- a/core/modules/comment/migration_templates/d6_comment_field.yml +++ b/core/modules/comment/migration_templates/d6_comment_field.yml @@ -3,15 +3,22 @@ label: Comment field configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable_per_comment_type + plugin: d6_node_type constants: entity_type: node type: comment process: entity_type: 'constants/entity_type' - field_name: comment_type + field_name: + - + plugin: migration_lookup + source: type + migration: d6_comment_type + - + plugin: skip_on_empty + method: row type: 'constants/type' - 'settings/comment_type': comment_type + 'settings/comment_type': '@field_name' destination: plugin: entity:field_storage_config dependencies: diff --git a/core/modules/comment/migration_templates/d6_comment_field_instance.yml b/core/modules/comment/migration_templates/d6_comment_field_instance.yml index d708619e1e..d3e7207b5b 100644 --- a/core/modules/comment/migration_templates/d6_comment_field_instance.yml +++ b/core/modules/comment/migration_templates/d6_comment_field_instance.yml @@ -3,7 +3,7 @@ label: Comment field instance configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable + plugin: d6_node_type constants: entity_type: node label: Comments @@ -13,12 +13,14 @@ process: label: 'constants/label' required: 'constants/required' field_name: - plugin: static_map - source: comment_subject_field - default_value: comment - map: - 0: comment_no_subject - bundle: node_type + - + plugin: migration_lookup + source: type + migration: d6_comment_type + - + plugin: skip_on_empty + method: row + bundle: type 'default_value/0/status': comment 'settings/default_mode': plugin: static_map diff --git a/core/modules/comment/migration_templates/d6_comment_type.yml b/core/modules/comment/migration_templates/d6_comment_type.yml index 69a2bd8651..d3d85e4ab7 100644 --- a/core/modules/comment/migration_templates/d6_comment_type.yml +++ b/core/modules/comment/migration_templates/d6_comment_type.yml @@ -3,13 +3,17 @@ label: Comment type migration_tags: - Drupal 6 source: - plugin: d6_comment_variable_per_comment_type + plugin: d6_node_type constants: entity_type: node + id_prefix: 'comment_node_' process: target_entity_type_id: 'constants/entity_type' - id: comment_type - label: label - description: description + id: + plugin: concat + source: + - 'constants/id_prefix' + - type + label: name destination: plugin: entity:comment_type diff --git a/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariable.php b/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariable.php deleted file mode 100644 index a56fb4dc21..0000000000 --- a/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariable.php +++ /dev/null @@ -1,108 +0,0 @@ -getCommentVariables()); - } - - /** - * {@inheritdoc} - */ - public function count() { - return count($this->getCommentVariables()); - } - - /** - * Retrieves the values of the comment variables grouped by node type. - * - * @return array - */ - protected function getCommentVariables() { - $comment_prefixes = array_keys($this->commentPrefixes()); - $variables = []; - $node_types = $this->select('node_type', 'nt') - ->fields('nt', ['type']) - ->execute() - ->fetchCol(); - foreach ($node_types as $node_type) { - foreach ($comment_prefixes as $prefix) { - $variables[] = $prefix . '_' . $node_type; - } - } - $return = []; - $values = $this->select('variable', 'v') - ->fields('v', ['name', 'value']) - ->condition('name', $variables, 'IN') - ->execute() - ->fetchAllKeyed(); - foreach ($node_types as $node_type) { - foreach ($comment_prefixes as $prefix) { - $name = $prefix . '_' . $node_type; - if (isset($values[$name])) { - $return[$node_type][$prefix] = unserialize($values[$name]); - } - } - } - // The return key will not be used so move it inside the row. This could - // not be done sooner because otherwise empty rows would be created with - // just the node type in it. - foreach ($return as $node_type => $data) { - $return[$node_type]['node_type'] = $node_type; - $return[$node_type]['comment_type'] = empty($data['comment_subject_field']) ? - 'comment_no_subject' : 'comment'; - } - return $return; - } - - /** - * {@inheritdoc} - */ - public function fields() { - return $this->commentPrefixes() + [ - 'node_type' => $this->t('The node type'), - 'comment_type' => $this->t('The comment type'), - ]; - } - - /** - * Comment related data for fields. - */ - protected function commentPrefixes() { - return [ - 'comment' => $this->t('Default comment setting'), - 'comment_default_mode' => $this->t('Default display mode'), - 'comment_default_order' => $this->t('Default display order'), - 'comment_default_per_page' => $this->t('Default comments per page'), - 'comment_controls' => $this->t('Comment controls'), - 'comment_anonymous' => $this->t('Anonymous commenting'), - 'comment_subject_field' => $this->t('Comment subject field'), - 'comment_preview' => $this->t('Preview comment'), - 'comment_form_location' => $this->t('Location of comment submission form'), - ]; - } - - /** - * {@inheritdoc} - */ - public function getIds() { - $ids['node_type']['type'] = 'string'; - return $ids; - } - -} diff --git a/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariablePerCommentType.php b/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariablePerCommentType.php deleted file mode 100644 index 0eea68608c..0000000000 --- a/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariablePerCommentType.php +++ /dev/null @@ -1,62 +0,0 @@ - $data) { - // Only 2 comment types depending on subject field visibility. - if (!empty($data['comment_subject_field'])) { - // Default label and description should be set in migration. - $return['comment'] = [ - 'comment_type' => 'comment', - 'label' => $this->t('Default comments'), - 'description' => $this->t('Allows commenting on content') - ]; - } - else { - // Provide a special comment type with hidden subject field. - $return['comment_no_subject'] = [ - 'comment_type' => 'comment_no_subject', - 'label' => $this->t('Comments without subject field'), - 'description' => $this->t('Allows commenting on content, comments without subject field') - ]; - } - } - return $return; - } - - /** - * {@inheritdoc} - */ - public function fields() { - return [ - 'comment_type' => $this->t('The comment type'), - 'label' => $this->t('The comment type label'), - 'description' => $this->t('The comment type description'), - ]; - } - - /** - * {@inheritdoc} - */ - public function getIds() { - $ids['comment_type']['type'] = 'string'; - return $ids; - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php new file mode 100644 index 0000000000..b00c7e79f0 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php @@ -0,0 +1,50 @@ +executeMigration('d6_comment_entity_display'); + } + + /** + * Asserts various aspects of the display of a node type comment field. + * + * @param string $node_type + * The node type ID. + */ + protected function assertComponent($node_type) { + $component = entity_get_display('node', $node_type, 'default') + ->getComponent('comment_node_' . $node_type); + + $this->assertInternalType('array', $component); + $this->assertSame('hidden', $component['label']); + $this->assertSame('comment_default', $component['type']); + $this->assertSame(20, $component['weight']); + } + + /** + * Tests comment variables migrated into an entity display. + */ + public function testCommentEntityDisplay() { + $this->assertComponent('page'); + $this->assertComponent('story'); + $this->assertComponent('article'); + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php new file mode 100644 index 0000000000..6bc312204e --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php @@ -0,0 +1,75 @@ +installConfig(['comment']); + $this->executeMigrations([ + 'd6_comment_type', + 'd6_comment_entity_form_display_subject', + ]); + } + + /** + * Asserts that the comment subject field is visible for a node type. + * + * @param string $node_type + * The node type ID. + */ + protected function assertSubjectVisible($node_type) { + $component = entity_get_form_display('comment', "comment_node_$node_type", 'default') + ->getComponent('subject'); + + $this->assertInternalType('array', $component); + $this->assertSame('string_textfield', $component['type']); + $this->assertSame(10, $component['weight']); + } + + /** + * Asserts that the comment subject field is not visible for a node type. + * + * @param string $node_type + * The node type ID. + */ + protected function assertSubjectNotVisible($node_type) { + $component = entity_get_form_display('comment', "comment_node_$node_type", 'default') + ->getComponent('subject'); + + $this->assertNull($component); + } + + /** + * Tests comment subject variable migrated into an entity display. + */ + public function testCommentEntityFormDisplay() { + $this->assertSubjectVisible('article'); + $this->assertSubjectVisible('company'); + $this->assertSubjectVisible('employee'); + $this->assertSubjectVisible('page'); + $this->assertSubjectVisible('sponsor'); + $this->assertSubjectNotVisible('story'); + $this->assertSubjectVisible('test_event'); + $this->assertSubjectVisible('test_page'); + $this->assertSubjectVisible('test_planet'); + $this->assertSubjectVisible('test_story'); + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php new file mode 100644 index 0000000000..46eadb5865 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php @@ -0,0 +1,49 @@ +executeMigration('d6_comment_entity_form_display'); + } + + /** + * Asserts various aspects of the form display of a node type comment field. + * + * @param string $node_type + * The node type ID. + */ + protected function assertComponent($node_type) { + $component = entity_get_form_display('node', $node_type, 'default') + ->getComponent('comment_node_' . $node_type); + + $this->assertInternalType('array', $component); + $this->assertSame('comment_default', $component['type']); + $this->assertSame(20, $component['weight']); + } + + /** + * Tests comment variables migrated into an entity display. + */ + public function testCommentEntityFormDisplay() { + $this->assertComponent('page'); + $this->assertComponent('article'); + $this->assertComponent('story'); + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php new file mode 100644 index 0000000000..7651717092 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php @@ -0,0 +1,71 @@ +installConfig(['comment']); + $this->migrateContentTypes(); + $this->executeMigrations([ + 'd6_comment_type', + 'd6_comment_field', + 'd6_comment_field_instance', + ]); + } + + /** + * Asserts various aspects of a comment field for a node type. + * + * @param string $node_type + * The node type ID. + * @param mixed $default_mode + * The expected default comment mode. + * @param int $per_page + * The expected number of comments per page. + * @param int $anonymous + * Whether anonymous commenting is expected to be enabled. + * @param bool $form_location + * The location of the comment form. + * @param int $preview + * Whether previewing comments is expected to be enabled. + */ + protected function assertCommentField($node_type, $default_mode, $per_page, $anonymous, $form_location, $preview) { + $id = "node.$node_type.comment_node_$node_type"; + $field = FieldConfig::load($id); + + $this->assertInstanceOf(FieldConfig::class, $field); + $this->assertSame($default_mode, $field->getSetting('default_mode')); + $this->assertSame($per_page, $field->getSetting('per_page')); + $this->assertSame($anonymous, $field->getSetting('anonymous')); + $this->assertSame($form_location, $field->getSetting('form_location')); + $this->assertSame($preview, $field->getSetting('preview')); + } + + /** + * Test the migrated field instance values. + */ + public function testCommentFieldInstance() { + $this->assertCommentField('page', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); + $this->assertCommentField('story', CommentManagerInterface::COMMENT_MODE_FLAT, 70, 1, FALSE, 0); + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php new file mode 100644 index 0000000000..dc71a63e3b --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php @@ -0,0 +1,63 @@ +installConfig(['comment']); + $this->migrateContentTypes(); + $this->executeMigrations(['d6_comment_type', 'd6_comment_field']); + } + + /** + * Asserts the existence of a node comment field. + * + * @param string $comment_type + * The comment type ID. + */ + protected function assertCommentField($comment_type) { + $field = FieldStorageConfig::load("node.$comment_type"); + + $this->assertInstanceOf(FieldStorageConfig::class, $field); + $this->assertSame('comment', $field->getType()); + $this->assertSame('node', $field->getTargetEntityTypeId()); + $this->assertSame($comment_type, $field->getSetting('comment_type')); + } + + /** + * Tests the creation of a comment field for each node type. + */ + public function testCommentField() { + $this->assertCommentField('comment_node_article'); + $this->assertCommentField('comment_node_company'); + $this->assertCommentField('comment_node_employee'); + $this->assertCommentField('comment_node_event'); + $this->assertCommentField('comment_node_forum'); + $this->assertCommentField('comment_node_page'); + $this->assertCommentField('comment_node_sponsor'); + $this->assertCommentField('comment_node_story'); + $this->assertCommentField('comment_node_test_event'); + $this->assertCommentField('comment_node_test_page'); + $this->assertCommentField('comment_node_test_planet'); + $this->assertCommentField('comment_node_test_story'); + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php index c28be63b97..339fc5f0d6 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php @@ -32,10 +32,22 @@ protected function setUp() { * Tests the Drupal 6 to Drupal 8 comment type migration. */ public function testCommentType() { - $comment_type = CommentType::load('comment'); - $this->assertIdentical('node', $comment_type->getTargetEntityTypeId()); - $comment_type = CommentType::load('comment_no_subject'); - $this->assertIdentical('node', $comment_type->getTargetEntityTypeId()); + // There should be a comment type for each node type. + $comment_types = CommentType::loadMultiple([ + 'comment_node_article', + 'comment_node_company', + 'comment_node_employee', + 'comment_node_event', + 'comment_node_forum', + 'comment_node_page', + 'comment_node_sponsor', + 'comment_node_story', + 'comment_node_test_event', + 'comment_node_test_page', + 'comment_node_test_planet', + 'comment_node_test_story', + ]); + $this->assertCount(12, $comment_types); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityDisplayTest.php deleted file mode 100644 index baa28bc549..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityDisplayTest.php +++ /dev/null @@ -1,39 +0,0 @@ -executeMigration('d6_comment_entity_display'); - } - - /** - * Tests comment variables migrated into an entity display. - */ - public function testCommentEntityDisplay() { - foreach (['page', 'story', 'article'] as $type) { - $component = EntityViewDisplay::load('node.' . $type . '.default')->getComponent('comment'); - $this->assertIdentical('hidden', $component['label']); - $this->assertIdentical('comment_default', $component['type']); - $this->assertIdentical(20, $component['weight']); - } - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplaySubjectTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplaySubjectTest.php deleted file mode 100644 index 31e61e0a65..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplaySubjectTest.php +++ /dev/null @@ -1,45 +0,0 @@ -installConfig(['comment']); - $this->executeMigrations([ - 'd6_comment_type', - 'd6_comment_entity_form_display_subject', - ]); - } - - /** - * Tests comment subject variable migrated into an entity display. - */ - public function testCommentEntityFormDisplay() { - $component = EntityFormDisplay::load('comment.comment.default') - ->getComponent('subject'); - $this->assertIdentical('string_textfield', $component['type']); - $this->assertIdentical(10, $component['weight']); - $component = EntityFormDisplay::load('comment.comment_no_subject.default') - ->getComponent('subject'); - $this->assertNull($component); - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplayTest.php deleted file mode 100644 index 818f9b87ea..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplayTest.php +++ /dev/null @@ -1,39 +0,0 @@ -executeMigration('d6_comment_entity_form_display'); - } - - /** - * Tests comment variables migrated into an entity display. - */ - public function testCommentEntityFormDisplay() { - foreach (['page', 'article', 'story'] as $type) { - $component = EntityFormDisplay::load('node.' . $type . '.default') - ->getComponent('comment'); - $this->assertIdentical('comment_default', $component['type']); - $this->assertIdentical(20, $component['weight']); - } - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableFieldTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableFieldTest.php deleted file mode 100644 index e2a2189559..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableFieldTest.php +++ /dev/null @@ -1,37 +0,0 @@ -installConfig(['comment']); - $this->migrateContentTypes(); - $this->executeMigrations(['d6_comment_type', 'd6_comment_field']); - } - - /** - * Tests comment variables migrated into a field entity. - */ - public function testCommentField() { - $this->assertTrue(is_object(FieldStorageConfig::load('node.comment'))); - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableInstanceTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableInstanceTest.php deleted file mode 100644 index 90b256fb14..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableInstanceTest.php +++ /dev/null @@ -1,60 +0,0 @@ -installConfig(['comment']); - $this->migrateContentTypes(); - $this->executeMigrations([ - 'd6_comment_type', - 'd6_comment_field', - 'd6_comment_field_instance', - ]); - } - - /** - * Test the migrated field instance values. - */ - public function testCommentFieldInstance() { - $node = Node::create(['type' => 'page']); - $this->assertIdentical(0, $node->comment->status); - $this->assertIdentical('comment', $node->comment->getFieldDefinition()->getName()); - $settings = $node->comment->getFieldDefinition()->getSettings(); - $this->assertIdentical(CommentManagerInterface::COMMENT_MODE_THREADED, $settings['default_mode']); - $this->assertIdentical(50, $settings['per_page']); - $this->assertFalse($settings['anonymous']); - $this->assertFalse($settings['form_location']); - $this->assertTrue($settings['preview']); - - $node = Node::create(['type' => 'story']); - $this->assertIdentical(2, $node->comment_no_subject->status); - $this->assertIdentical('comment_no_subject', $node->comment_no_subject->getFieldDefinition()->getName()); - $settings = $node->comment_no_subject->getFieldDefinition()->getSettings(); - $this->assertIdentical(CommentManagerInterface::COMMENT_MODE_FLAT, $settings['default_mode']); - $this->assertIdentical(70, $settings['per_page']); - $this->assertTrue($settings['anonymous']); - $this->assertFalse($settings['form_location']); - $this->assertFalse($settings['preview']); - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariablePerCommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariablePerCommentTypeTest.php deleted file mode 100644 index dd1b1fd06c..0000000000 --- a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariablePerCommentTypeTest.php +++ /dev/null @@ -1,62 +0,0 @@ - 'page', - ], - [ - 'type' => 'story', - ], - ]; - - $tests[0]['source_data']['variable'] = [ - [ - 'name' => 'comment_subject_field_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_subject_field_story', - 'value' => serialize(0), - ], - ]; - - // The expected results. - // Each result will also include a label and description, but those are - // static values set by the source plugin and don't need to be asserted. - $tests[0]['expected_data'] = [ - [ - 'comment_type' => 'comment', - ], - [ - 'comment_type' => 'comment_no_subject', - ], - ]; - - return $tests; - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariableTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariableTest.php deleted file mode 100644 index a84c776b77..0000000000 --- a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariableTest.php +++ /dev/null @@ -1,92 +0,0 @@ - 'page', - ], - ]; - - $tests[0]['source_data']['variable'] = [ - [ - 'name' => 'comment_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_default_mode_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_default_order_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_default_per_page_page', - 'value' => serialize(50), - ], - [ - 'name' => 'comment_controls_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_anonymous_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_subject_field_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_preview_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_form_location_page', - 'value' => serialize(1), - ], - ]; - - // The expected results. - $tests[0]['expected_data'] = [ - [ - 'comment' => '1', - 'comment_default_mode' => '1', - 'comment_default_order' => '1', - 'comment_default_per_page' => '50', - 'comment_controls' => '1', - 'comment_anonymous' => '1', - 'comment_subject_field' => '1', - 'comment_preview' => '1', - 'comment_form_location' => '1', - 'node_type' => 'page', - 'comment_type' => 'comment', - ], - ]; - - return $tests; - } - -} diff --git a/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php b/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php index b5a66ce7e2..1176b38c60 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php @@ -62,7 +62,7 @@ public function query() { * {@inheritdoc} */ public function fields() { - return [ + $fields = [ 'type' => $this->t('Machine name of the node type.'), 'name' => $this->t('Human name of the node type.'), 'module' => $this->t('The module providing the node type.'), @@ -78,6 +78,30 @@ public function fields() { 'orig_type' => $this->t('The original type.'), 'teaser_length' => $this->t('Teaser length'), ]; + if ($this->moduleExists('comment')) { + $fields += $this->getCommentFields(); + } + return $fields; + } + + /** + * Returns the fields containing comment settings for each node type. + * + * @return string[] + * An associative array of field descriptions, keyed by field. + */ + protected function getCommentFields() { + return [ + 'comment' => $this->t('Default comment setting'), + 'comment_default_mode' => $this->t('Default display mode'), + 'comment_default_order' => $this->t('Default display order'), + 'comment_default_per_page' => $this->t('Default comments per page'), + 'comment_controls' => $this->t('Comment controls'), + 'comment_anonymous' => $this->t('Anonymous commenting'), + 'comment_subject_field' => $this->t('Comment subject field'), + 'comment_preview' => $this->t('Preview comment'), + 'comment_form_location' => $this->t('Location of comment submission form'), + ]; } /** @@ -111,6 +135,13 @@ public function prepareRow(Row $row) { $row->setSourceProperty('available_menus', [$default_node_menu]); $row->setSourceProperty('parent', $default_node_menu . ':'); } + + if ($this->moduleExists('comment')) { + foreach (array_keys($this->getCommentFields()) as $field) { + $row->setSourceProperty($field, $this->variableGet($field . '_' . $type, NULL)); + } + } + return parent::prepareRow($row); }