Commit 5b3fdce4 authored by catch's avatar catch

Issue #2887142 by maxocub, phenaproxima, Jo Fitzgerald, Adita, heddn,...

Issue #2887142 by maxocub, phenaproxima, Jo Fitzgerald, Adita, heddn, andypost: NodeType source plugin should include comment information
parent e8875156
......@@ -16,10 +16,15 @@ process:
source: pid
entity_id: nid
entity_type: 'constants/entity_type'
# field_name & comment_type is calculated in
# \Drupal\migrate_drupal\Plugin\migrate\source\d6\Comment::prepareRow()
field_name: field_name
comment_type: comment_type
comment_type:
-
plugin: migration_lookup
source: type
migration: d6_comment_type
-
plugin: skip_on_empty
method: row
field_name: '@comment_type'
subject: subject
uid: uid
name: name
......
......@@ -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:
......
......@@ -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:
......
......@@ -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
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
default_value: false
destination:
plugin: component_entity_form_display
migration_dependencies:
......
......@@ -3,20 +3,24 @@ 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:
module:
- comment
migration_dependencies:
required:
- d6_comment_type
......@@ -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,13 +13,24 @@ process:
label: 'constants/label'
required: 'constants/required'
field_name:
-
plugin: migration_lookup
source: type
migration: d6_comment_type
-
plugin: skip_on_empty
method: row
bundle: type
'default_value/0/status':
# We're using static_map instead of default_value otherwise if the source
# is 0, the default value of 1 would be used.
plugin: static_map
source: comment_subject_field
default_value: comment
source: comment
map:
0: comment_no_subject
bundle: node_type
'default_value/0/status': comment
0: 0
1: 1
2: 2
default_value: 2
'settings/default_mode':
plugin: static_map
source: comment_default_mode
......@@ -32,13 +43,31 @@ process:
3: 1
# COMMENT_MODE_THREADED_EXPANDED --> COMMENT_MODE_THREADED
4: 1
'settings/per_page': comment_default_per_page
'settings/anonymous': comment_anonymous
'settings/form_location': comment_form_location
'settings/preview': comment_preview
default_value: 1
'settings/per_page':
plugin: default_value
source: comment_default_per_page
default_value: 50
'settings/anonymous':
plugin: default_value
source: comment_anonymous
default_value: 0
'settings/form_location':
plugin: default_value
source: comment_form_location
default_value: 0
'settings/preview':
# We're using static_map instead of default_value otherwise if the source
# is 0, the default value of 1 would be used.
plugin: static_map
source: comment_preview
map:
0: 0
1: 1
default_value: 1
destination:
plugin: entity:field_config
migration_dependencies:
required:
- d6_comment_field
- d6_node_type
- d6_comment_field
......@@ -3,13 +3,31 @@ 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_'
label_suffix: 'comment'
process:
target_entity_type_id: 'constants/entity_type'
id: comment_type
label: label
description: description
id:
-
plugin: concat
source:
- 'constants/id_prefix'
- type
-
plugin: static_map
bypass: true
# The Forum module provides its own comment type (comment_forum), which we
# want to reuse if it exists.
map:
comment_node_forum: comment_forum
label:
plugin: concat
source:
- name
- 'constants/label_suffix'
delimiter: ' '
destination:
plugin: entity:comment_type
......@@ -19,7 +19,7 @@ process:
comment_type:
-
plugin: migration_lookup
source: comment_type
source: node_type
migration: d7_comment_type
-
plugin: skip_on_empty
......
......@@ -3,7 +3,7 @@ label: Comment display configuration
migration_tags:
- Drupal 7
source:
plugin: d7_comment_type
plugin: d7_node_type
constants:
entity_type: node
view_mode: default
......@@ -16,14 +16,14 @@ process:
field_name:
-
plugin: migration_lookup
source: bundle
source: type
migration: d7_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:
......
......@@ -3,20 +3,26 @@ label: Comment field form display configuration
migration_tags:
- Drupal 7
source:
plugin: d7_comment_type
plugin: d7_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: d7_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:
......
......@@ -3,7 +3,7 @@ label: Comment subject form display configuration
migration_tags:
- Drupal 7
source:
plugin: d7_comment_type
plugin: d7_node_type
constants:
entity_type: comment
field_name: subject
......@@ -16,20 +16,23 @@ process:
field_name: 'constants/field_name'
form_mode: 'constants/form_mode'
options: 'constants/options'
hidden:
plugin: static_map
source: subject
map:
0: true
1: false
bundle:
-
plugin: migration_lookup
source: bundle
source: type
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
hidden:
plugin: static_map
source: comment_subject_field
map:
# If comment_subject_field = FALSE, then hidden = TRUE.
0: true
# If comment_subject_field = TRUE, then hidden = FALSE.
1: false
default_value: false
destination:
plugin: component_entity_form_display
migration_dependencies:
......
......@@ -3,7 +3,7 @@ label: Comment field configuration
migration_tags:
- Drupal 7
source:
plugin: d7_comment_type
plugin: d7_node_type
constants:
entity_type: node
type: comment
......@@ -12,7 +12,7 @@ process:
field_name:
-
plugin: migration_lookup
source: bundle
source: type
migration: d7_comment_type
-
plugin: skip_on_empty
......
......@@ -3,7 +3,7 @@ label: Comment field instance configuration
migration_tags:
- Drupal 7
source:
plugin: d7_comment_type
plugin: d7_node_type
constants:
entity_type: node
label: Comments
......@@ -15,20 +15,56 @@ process:
field_name:
-
plugin: migration_lookup
source: bundle
source: type
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
bundle: node_type
'default_value/0/status': 'constants/required'
'settings/default_mode': default_mode
'settings/per_page': per_page
'settings/anonymous': anonymous
'settings/form_location': form_location
'settings/preview': preview
bundle: type
'default_value/0/status':
# We're using static_map instead of default_value otherwise if the source
# is 0, the default value of 1 would be used.
plugin: static_map
source: comment
map:
0: 0
1: 1
2: 2
default_value: 2
'settings/default_mode':
# We're using static_map instead of default_value otherwise if the source
# is 0, the default value of 1 would be used.
plugin: static_map
source: comment_default_mode
map:
0: 0
1: 1
default_value: 1
'settings/per_page':
plugin: default_value
source: comment_default_per_page
default_value: 50
'settings/anonymous':
plugin: default_value
source: comment_anonymous
default_value: 0
'settings/form_location':
plugin: default_value
source: comment_form_location
default_value: 0
'settings/preview':
# We're using static_map instead of default_value otherwise if the source
# is 0, the default value of 1 would be used.
plugin: static_map
source: comment_preview
map:
0: 0
1: 1
2: 2
default_value: 1
destination:
plugin: entity:field_config
migration_dependencies:
required:
- d7_node_type
- d7_comment_field
......@@ -3,22 +3,31 @@ label: Comment type
migration_tags:
- Drupal 7
source:
plugin: d7_comment_type
plugin: d7_node_type
constants:
entity_type: node
id_prefix: 'comment_node_'
label_suffix: 'comment'
process:
target_entity_type_id: 'constants/entity_type'
id:
-
plugin: concat
source:
- 'constants/id_prefix'
- type
-
plugin: static_map
source: bundle
bypass: true
# The Forum module provides its own comment type (comment_forum), which we
# want to reuse if it exists.
map:
comment_node_forum: comment_forum
label: label
label:
plugin: concat
source:
- name
- 'constants/label_suffix'
delimiter: ' '
destination:
plugin: entity:comment_type
migration_dependencies:
required:
- d7_node_type
......@@ -34,6 +34,20 @@ public function query() {
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
return parent::prepareRow($this->prepareComment($row));
}
/**
* This is a backward compatibility layer for the deprecated migrate source
* plugins d6_comment_variable and d6_comment_variable_per_comment_type.
*
* @param \Drupal\migrate\Row $row
* The row from the source to process.
* @return \Drupal\migrate\Row
* The row object.
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x.
*/
protected function prepareComment(Row $row) {
if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) {
// Comment subject visible.
$row->setSourceProperty('field_name', 'comment');
......@@ -43,10 +57,11 @@ public function prepareRow(Row $row) {
$row->setSourceProperty('field_name', 'comment_no_subject');
$row->setSourceProperty('comment_type', 'comment_no_subject');
}
// In D6, status=0 means published, while in D8 means the opposite.
// See https://www.drupal.org/node/237636.
$row->setSourceProperty('status', !$row->getSourceProperty('status'));
return parent::prepareRow($row);
return $row;
}
/**
......
......@@ -2,6 +2,8 @@
namespace Drupal\comment\Plugin\migrate\source\d6;
@trigger_error('CommentVariable is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.', E_USER_DEPRECATED);
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\migrate\Plugin\migrate\source\DummyQueryTrait;
......@@ -10,6 +12,9 @@
* id = "d6_comment_variable",
* source_module = "comment"
* )
*
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
* \Drupal\node\Plugin\migrate\source\d6\NodeType instead.
*/
class CommentVariable extends DrupalSqlBase {
......
......@@ -2,11 +2,16 @@
namespace Drupal\comment\Plugin\migrate\source\d6;
@trigger_error('CommentVariablePerCommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.', E_USER_DEPRECATED);
/**
* @MigrateSource(
* id = "d6_comment_variable_per_comment_type",
* source_module = "comment"
* )
*
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
* \Drupal\node\Plugin\migrate\source\d6\NodeType instead.
*/
class CommentVariablePerCommentType extends CommentVariable {
......
......@@ -2,6 +2,8 @@
namespace Drupal\comment\Plugin\migrate\source\d7;
@trigger_error('CommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d7\NodeType instead.', E_USER_DEPRECATED);
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
......@@ -13,6 +15,9 @@
* id = "d7_comment_type",
* source_module = "comment"
* )
*
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
* \Drupal\node\Plugin\migrate\source\d7\NodeType instead.
*/
class CommentType extends DrupalSqlBase {
......
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests the migration of comment entity displays from Drupal 6.
*
* @group comment
* @group migrate_drupal_6
*/
class MigrateCommentEntityDisplayTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'menu_ui'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->migrateContentTypes();
$this->executeMigrations([
'd6_node_type',
'd6_comment_type',
'd6_comment_field',
'd6_comment_field_instance',
'd6_comment_entity_display',
]);
}
/**
* Asserts various aspects of a comment component in an entity view display.
*
* @param string $id
* The entity ID.
* @param string $component_id
* The ID of the display component.
*/
protected function assertDisplay($id, $component_id) {
$component = EntityViewDisplay::load($id)->getComponent($component_id);
$this->assertInternalType('array', $component);
$this->assertSame('hidden', $component['label']);
$this->assertSame('comment_default', $component['type']);
$this->assertSame(20, $component['weight']);
}
/**
* Tests the migrated display configuration.
*/
public function testMigration() {
$this->assertDisplay('node.article.default', 'comment_node_article');
$this->assertDisplay('node.company.default', 'comment_node_company');
$this->assertDisplay('node.employee.default', 'comment_node_employee');
$this->assertDisplay('node.event.default', 'comment_node_event');
$this->assertDisplay('node.forum.default', 'comment_forum');
$this->assertDisplay('node.page.default', 'comment_node_page');
$this->assertDisplay('node.sponsor.default', 'comment_node_sponsor');
$this->assertDisplay('node.story.default', 'comment_node_story');
$this->assertDisplay('node.test_event.default', 'comment_node_test_event');
$this->assertDisplay('node.test_page.default', 'comment_node_test_page');
$this->assertDisplay('node.test_planet.default', 'comment_node_test_planet');
$this->assertDisplay('node.test_story.default', 'comment_node_test_story');
}
}
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests the migration of comment form's subject display from Drupal 6.
*
* @group comment
* @group migrate_drupal_6
*/
class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->executeMigrations([