Commit 5fb97954 authored by catch's avatar catch

Issue #2565931 by quietone, jofitz, shaktik, sokru, mikeryan, clemens.tolboom,...

Issue #2565931 by quietone, jofitz, shaktik, sokru, mikeryan, clemens.tolboom, kapilkumar0324, anushrikumari, wturrell, benjifisher, mikelutz: Handle long comment bundle names
parent dd164ae6
......@@ -24,6 +24,12 @@ process:
# want to reuse if it exists.
map:
comment_node_forum: comment_forum
-
plugin: make_unique_entity_field
entity_type: comment_type
field: id
length: 30
migrated: true
label:
plugin: concat
source:
......
......@@ -24,6 +24,12 @@ process:
# want to reuse if it exists.
map:
comment_node_forum: comment_forum
-
plugin: make_unique_entity_field
entity_type: comment_type
field: id
length: 30
migrated: true
label:
plugin: concat
source:
......
......@@ -52,6 +52,7 @@ public function testMigration() {
$this->assertEntity('comment_node_test_page', 'Migrate test page comment');
$this->assertEntity('comment_node_test_planet', 'Migrate test planet comment');
$this->assertEntity('comment_node_test_story', 'Migrate test story comment');
$this->assertEntity('comment_node_a_thirty_two_char', 'Test long name comment');
}
/**
......
......@@ -58,6 +58,7 @@ public function testMigration() {
$this->assertEntity('comment_forum', 'Forum topic comment');
$this->assertEntity('comment_node_page', 'Basic page comment');
$this->assertEntity('comment_node_test_content_type', 'Test content type comment');
$this->assertEntity('comment_node_a_thirty_two_char', 'Test long name comment');
}
/**
......
......@@ -31,11 +31,17 @@ process:
# that might already exist before this migration is run. See
# d7_comment_type.yml or more information.
bundle:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
-
plugin: migration_lookup
migration: d7_field_instance
source:
- entity_type
- bundle
- field_name
-
plugin: extract
index:
- 1
view_mode:
-
plugin: migration_lookup
......
......@@ -19,12 +19,17 @@ process:
# The bundle needs to be statically mapped in order to support comment types
# that might already exist before this migration is run. See
# d7_comment_type.yml for more information.
bundle:
bundle_mapped:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
bundle:
plugin: field_bundle
source:
- entity_type
- '@bundle_mapped'
label: label
description: description
required: required
......
......@@ -31,11 +31,17 @@ process:
# that might already exist before this migration is run. See
# d7_comment_type.yml for more information.
bundle:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
-
plugin: migration_lookup
migration: d7_field_instance
source:
- entity_type
- bundle
- field_name
-
plugin: extract
index:
- 1
form_mode: 'constants/form_mode'
field_name: field_name
entity_type: entity_type
......
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Determines the bundle for a field.
*
* The field bundle process plugin is used to get the destination bundle name
* for a field. This is necessary because the bundle names used for comments in
* legacy versions of Drupal are no longer used.
*
* Available configuration keys:
* - source: The input value - must be an array.
*
* Examples:
*
* @code
* process:
* bundle:
* plugin: field_bundle
* source
* - entity_type
* - bundle
* @endcode
*
* If 'bundle' is 'article' and 'entity_type' is node then 'article' is
* returned.
*
* @code
* process:
* bundle:
* plugin: field_bundle
* source
* - entity_type
* - bundle
* @endcode
*
* If 'bundle' is 'comment_node_a_thirty_two_character_name' and 'entity_type'
* is blog then a lookup is performed on the comment type migration so that the
* migrated bundle name for 'comment_node_a_thirty_two_character_name' is
* returned. That name will be truncated to 'comment_node_a_thirty_two_char'.
*
* @see core/modules/comment/migrations/d7_comment_type.yml
* @see core/modules/field/migrations/d7_field_instance.yml
*
* * @MigrateProcessPlugin(
* id = "field_bundle"
* )
*/
class FieldBundle extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The migrate lookup service.
*
* @var \Drupal\migrate\MigrateLookupInterface
*/
protected $migrateLookup;
/**
* Constructs a ProcessField plugin.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate\MigrateLookupInterface $migrate_lookup
* The migrate lookup service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateLookupInterface $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migrateLookup = $migrate_lookup;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('migrate.lookup')
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$entity_type, $bundle] = $value;
$lookup_result = NULL;
// For comment entity types get the destination bundle from the
// d7_comment_type migration, if it exists.
if ($entity_type === 'comment' && $bundle != 'comment_forum') {
$value = preg_replace('/comment_node_/', NULL, $bundle);
$migration = 'd7_comment_type';
$lookup_result = $this->migrateLookup->lookup($migration, [$value]);
$lookup_result = empty($lookup_result) ? NULL : reset($lookup_result[0]);
}
return $lookup_result ? $lookup_result : $bundle;
}
}
......@@ -15,13 +15,15 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['menu_ui', 'node'];
protected static $modules = ['comment', 'menu_ui', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig(['comment']);
$this->executeMigration('d6_comment_type');
$this->migrateFields();
}
......@@ -225,6 +227,11 @@ public function testEntityDisplaySettings() {
$this->assertSame('entity_reference_label', $component['type']);
// The default user reference formatter links to the referenced user.
$this->assertTrue($component['settings']['link']);
$display = EntityViewDisplay::load('comment.comment_node_a_thirty_two_char.default');
$component = $display->getComponent('comment_body');
$this->assertIsArray($component);
$this->assertSame('text_default', $component['type']);
}
}
......@@ -17,13 +17,15 @@ class MigrateFieldInstanceTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['menu_ui', 'node'];
protected static $modules = ['comment', 'menu_ui', 'node'];
/**
* Tests migration of file variables to file.settings.yml.
*/
public function testFieldInstanceMigration() {
$this->migrateFields();
$this->installConfig(['comment']);
$this->executeMigration('d6_comment_type');
$entity = Node::create(['type' => 'story']);
// Test a text field.
......@@ -166,6 +168,10 @@ public function testFieldInstanceMigration() {
$field = FieldConfig::load('node.employee.field_sync');
$this->assertInstanceOf(FieldConfig::class, $field);
$this->assertFalse($field->isTranslatable());
// Test a comment with a long name.
$field = FieldConfig::load('comment.comment_node_a_thirty_two_char.comment_body');
$this->assertInstanceOf(FieldConfig::class, $field);
}
/**
......
......@@ -15,13 +15,15 @@ class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['menu_ui'];
protected static $modules = ['comment', 'menu_ui'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig(['comment']);
$this->executeMigration('d6_comment_type');
$this->migrateFields();
}
......@@ -124,6 +126,11 @@ public function testWidgetSettings() {
->getComponent('field_commander');
$this->assertIsArray($component);
$this->assertSame('options_select', $component['type']);
$component = $display_repository->getFormDisplay('comment', 'comment_node_a_thirty_two_char', 'default')
->getComponent('comment_body');
$this->assertIsArray($component);
$this->assertSame('text_textarea', $component['type']);
}
}
......@@ -106,6 +106,9 @@ public function testMigration() {
$this->assertComponent('comment.comment_node_test_content_type.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertComponent('comment.comment_node_test_content_type.default', 'field_integer', 'number_integer', 'above', 1);
$this->assertEntity('comment.comment_node_a_thirty_two_char.default');
$this->assertComponent('comment.comment_node_a_thirty_two_char.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('node.article.default');
$this->assertComponent('node.article.default', 'body', 'text_default', 'hidden', 0);
$this->assertComponent('node.article.default', 'field_tags', 'entity_reference_label', 'above', 10);
......
......@@ -131,6 +131,7 @@ public function testFieldInstances() {
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_text', 'Text', 'string', FALSE, FALSE);
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE, TRUE);
$this->assertEntity('comment.comment_node_a_thirty_two_char.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE, FALSE);
$this->assertLinkFields('node.test_content_type.field_link', DRUPAL_OPTIONAL);
......
......@@ -136,6 +136,9 @@ public function testWidgetSettings() {
$this->assertComponent('comment.comment_node_test_content_type.default', 'comment_body', 'text_textarea', 0);
$this->assertComponent('comment.comment_node_test_content_type.default', 'field_integer', 'number', 2);
$this->assertEntity('comment.comment_node_a_thirty_two_char.default', 'comment', 'comment_node_a_thirty_two_char');
$this->assertComponent('comment.comment_node_a_thirty_two_char.default', 'comment_body', 'text_textarea', 0);
$this->assertEntity('taxonomy_term.test_vocabulary.default', 'taxonomy_term', 'test_vocabulary');
$this->assertComponent('comment.comment_node_test_content_type.default', 'field_integer', 'number', 2);
}
......
......@@ -46177,6 +46177,22 @@
'locked' => '0',
'orig_type' => 'test_story',
))
->values(array(
'type' => 'a_thirty_two_character_type_name',
'name' => 'Test long name',
'module' => 'node',
'description' => '',
'help' => '',
'has_title' => '1',
'title_label' => 'Title',
'has_body' => '1',
'body_label' => 'Body',
'min_word_count' => '0',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'orig_type' => '',
))
->execute();
$connection->schema()->createTable('permission', array(
'fields' => array(
......@@ -5339,6 +5339,24 @@
'data' => 'a:7:{s:5:"label";s:7:"termrss";s:6:"widget";a:5:{s:6:"weight";s:2:"16";s:4:"type";s:15:"options_buttons";s:6:"module";s:7:"options";s:6:"active";i:1;s:8:"settings";a:0:{}}s:8:"settings";a:2:{s:18:"user_register_form";b:0;s:23:"entity_translation_sync";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:36:"taxonomy_term_reference_rss_category";s:6:"weight";s:2:"14";s:8:"settings";a:0:{}s:6:"module";s:8:"taxonomy";}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}',
'deleted' => '0',
))
->values(array(
'id' => '86',
'field_id' => '1',
'field_name' => 'comment_body',
'entity_type' => 'comment',
'bundle' => 'comment_node_a_thirty_two_character_type_name',
'data' => 'a:6:{s:5:"label";s:7:"Comment";s:8:"settings";a:2:{s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:8:"required";b:1;s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:6:"weight";i:0;s:8:"settings";a:0:{}s:6:"module";s:4:"text";}}s:6:"widget";a:4:{s:4:"type";s:13:"text_textarea";s:8:"settings";a:1:{s:4:"rows";i:5;}s:6:"weight";i:0;s:6:"module";s:4:"text";}s:11:"description";s:0:"";}',
'deleted' => '0',
))
->values(array(
'id' => '87',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'a_thirty_two_character_type_name',
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
))
->execute();
$connection->schema()->createTable('field_data_body', array(
'fields' => array(
......@@ -44745,6 +44763,21 @@
'locked' => '0',
'disabled' => '0',
'orig_type' => 'et',
))
->values(array(
'type' => 'a_thirty_two_character_type_name',
'name' => 'Test long name',
'base' => 'node_content',
'module' => 'node',
'description' => '',
'help' => '',
'has_title' => '1',
'title_label' => 'Title',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'disabled' => '0',
'orig_type' => 'page',
))
->execute();
......@@ -80,6 +80,7 @@ public function setUp(): void {
'et' => 'comment_node_et',
'forum' => 'comment_forum',
'test_content_type' => 'comment_node_test_content_type',
'a_thirty_two_character_type_name' => 'a_thirty_two_character_type_name',
];
foreach ($node_types as $node_type => $comment_type) {
NodeType::create([
......@@ -97,6 +98,7 @@ public function setUp(): void {
Vocabulary::create(['vid' => 'test_vocabulary'])->save();
$this->executeMigrations([
'd7_field',
'd7_comment_type',
'd7_taxonomy_vocabulary',
'd7_field_instance',
]);
......@@ -283,8 +285,8 @@ public function testGetAllFields() {
$this->assertArrayHasKey('test_vocabulary', $actual_fields['taxonomy_term']);
$this->assertArrayHasKey('user', $actual_fields['user']);
$this->assertArrayHasKey('test_content_type', $actual_fields['node']);
$this->assertCount(7, $actual_fields['node']);
$this->assertCount(7, $actual_fields['comment']);
$this->assertCount(8, $actual_fields['node']);
$this->assertCount(8, $actual_fields['comment']);
$this->assertCount(22, $actual_fields['node']['test_content_type']);
foreach ($actual_fields as $entity_type_id => $bundles) {
foreach ($bundles as $bundle => $fields) {
......
......@@ -106,7 +106,7 @@ public function testMigrateUpgradeExecute() {
// Confirm there are only classic node migration map tables. This shows
// that only the classic migration will run.
$results = $this->nodeMigrateMapTableCount('6');
$this->assertSame(13, $results['node']);
$this->assertSame(14, $results['node']);
$this->assertSame(0, $results['node_complete']);
}
......
......@@ -77,13 +77,13 @@ protected function getEntityCounts() {
'comment' => 8,
// The 'standard' profile provides the 'comment' comment type, and the
// migration creates 12 comment types, one per node type.
'comment_type' => 13,
'comment_type' => 14,
'contact_form' => 5,
'contact_message' => 0,
'configurable_language' => 5,
'editor' => 2,
'field_config' => 99,
'field_storage_config' => 70,
'field_config' => 103,
'field_storage_config' => 71,
'file' => 7,
'filter_format' => 7,
'image_style' => 6,
......@@ -91,7 +91,7 @@ protected function getEntityCounts() {
'node' => 18,
// The 'book' module provides the 'book' node type, and the migration
// creates 12 node types.
'node_type' => 13,
'node_type' => 14,
'rdf_mapping' => 7,
'search_page' => 2,
'shortcut' => 2,
......@@ -107,11 +107,11 @@ protected function getEntityCounts() {
'menu_link_content' => 10,
'view' => 16,
'date_format' => 11,
'entity_form_display' => 29,
'entity_form_display' => 31,
'entity_form_mode' => 1,
'entity_view_display' => 58,
'entity_view_display' => 61,
'entity_view_mode' => 14,
'base_field_override' => 38,
'base_field_override' => 41,
];
}
......@@ -122,7 +122,7 @@ protected function getEntityCountsIncremental() {
$counts = $this->getEntityCounts();
$counts['block_content'] = 3;
$counts['comment'] = 9;
$counts['entity_view_display'] = 58;
$counts['entity_view_display'] = 61;
$counts['entity_view_mode'] = 14;
$counts['file'] = 8;
$counts['menu_link_content'] = 11;
......
......@@ -78,21 +78,21 @@ protected function getEntityCounts() {
'comment' => 4,
// The 'standard' profile provides the 'comment' comment type, and the
// migration creates 6 comment types, one per node type.
'comment_type' => 8,
'comment_type' => 9,
// Module 'language' comes with 'en', 'und', 'zxx'. Migration adds 'is'
// and 'fr'.
'configurable_language' => 5,
'contact_form' => 3,
'contact_message' => 0,
'editor' => 2,
'field_config' => 81,
'field_storage_config' => 62,
'field_config' => 84,
'field_storage_config' => 63,
'file' => 3,
'filter_format' => 7,
'image_style' => 7,
'language_content_settings' => 22,
'node' => 7,
'node_type' => 7,
'node_type' => 8,
'rdf_mapping' => 8,
'search_page' => 2,
'shortcut' => 6,
......@@ -108,9 +108,9 @@ protected function getEntityCounts() {
'menu_link_content' => 12,
'view' => 16,
'date_format' => 11,
'entity_form_display' => 22,
'entity_form_display' => 24,
'entity_form_mode' => 1,
'entity_view_display' => 33,
'entity_view_display' => 36,
'entity_view_mode' => 14,
'base_field_override' => 4,
];
......
......@@ -47,7 +47,7 @@ public function testNode() {
// Confirm there are only classic node migration map tables. This shows
// that only the classic migration ran.
$results = $this->nodeMigrateMapTableCount('6');
$this->assertSame(13, $results['node']);
$this->assertSame(14, $results['node']);
$this->assertSame(0, $results['node_complete']);
$node = Node::load(1);
$this->assertIdentical('1', $node->id(), 'Node 1 loaded.');
......
......@@ -86,6 +86,10 @@ public function testNodeType() {
$this->assertSame($expected_available_menus, $node_type_event->getThirdPartySetting('menu_ui', 'available_menus'));
$expected_parent = 'navigation:';
$this->assertSame($expected_parent, $node_type_event->getThirdPartySetting('menu_ui', 'parent'));
// Test the 32 character type name exists.
$node_type = NodeType::load('a_thirty_two_character_type_name');
$this->assertSame('a_thirty_two_character_type_name', $node_type->id());
}
}
......@@ -103,7 +103,7 @@ public function testNodeCompleteMigration() {
// that only the complete migration ran.
$results = $this->nodeMigrateMapTableCount('7');
$this->assertSame(0, $results['node']);
$this->assertSame(7, $results['node_complete']);
$this->assertSame(8, $results['node_complete']);
$db = \Drupal::database();
$this->assertEquals($this->expectedNodeFieldRevisionTable(), $db->select('node_field_revision', 'nr')
......
......@@ -150,7 +150,7 @@ public function testNode() {
// Confirm there are only classic node migration map tables. This shows
// that only the classic migration ran.
$results = $this->nodeMigrateMapTableCount('7');
$this->assertSame(8, $results['node']);
$this->assertSame(9, $results['node']);
$this->assertSame(0, $results['node_complete']);
$this->assertEntity(1, 'test_content_type', 'en', 'An English Node', '2', TRUE, '1421727515', '1441032132', TRUE, FALSE);
......
......@@ -80,6 +80,9 @@ public function testNodeType() {
$this->assertEntity('book', 'Book page', '<em>Books</em> have a built-in hierarchical navigation. Use for handbooks or tutorials.', '', TRUE, TRUE, $expected_available_menus, $expected_parent, "Body");
$this->assertEntity('forum', 'Forum topic', 'A <em>forum topic</em> starts a new discussion thread within a forum.', 'No name-calling, no flame wars. Be nice.', TRUE, FALSE, $expected_available_menus, $expected_parent, 'Body');
$this->assertEntity('page', 'Basic page', "Use <em>basic pages</em> for your static content, such as an 'About us' page.", 'Help text for basic pages', FALSE, FALSE, $expected_available_menus, $expected_parent, "Body");
// Test the 32 character type name exists.
$this->assertEntity('a_thirty_two_character_type_name', 'Test long name', '', '', TRUE, FALSE, NULL, NULL, "Body");
// This node type does not carry a body field.
$expected_available_menus = [
'main-menu',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment