Commit 5380355d authored by catch's avatar catch

Issue #2872660 by phenaproxima: Migrate D6 node reference fields to D8 entity...

Issue #2872660 by phenaproxima: Migrate D6 node reference fields to D8 entity reference field definitions
parent 6fe0f0d3
......@@ -20,6 +20,8 @@ process:
- type
- widget_type
map:
nodereference:
nodereference_select: entity_reference
number_integer:
number: integer
optionwidgets_select: list_integer
......
......@@ -163,6 +163,11 @@ process:
default: basic_string
int_phone:
default: basic_string
nodereference:
default: entity_reference_label
plain: entity_reference_label
full: entity_reference_entity_view
teaser: entity_reference_entity_view
-
plugin: field_type_defaults
"options/settings":
......@@ -173,6 +178,14 @@ process:
- module
- 'display_settings/format'
map:
nodereference:
default: { }
plain:
link: false
full:
view_mode: full
teaser:
view_mode: teaser
link:
default:
trim_length: '80'
......
......@@ -55,6 +55,7 @@ process:
optionwidgets_onoff: boolean_checkbox
optionwidgets_buttons: options_buttons
optionwidgets_select: options_select
nodereference_select: options_select
'options/settings':
-
plugin: field_instance_widget_settings
......
......@@ -198,6 +198,24 @@ public function testEntityDisplaySettings() {
// Test hidden field.
$this->assertComponentNotExists('node.test_planet.teaser', 'field_test_text_single_checkbox');
// Test a node reference field, which should be migrated to an entity
// reference field.
$display = EntityViewDisplay::load('node.employee.default');
$component = $display->getComponent('field_company');
$this->assertInternalType('array', $component);
$this->assertSame('entity_reference_label', $component['type']);
// The default node reference formatter shows the referenced node's title
// as a link.
$this->assertTrue($component['settings']['link']);
$display = EntityViewDisplay::load('node.employee.teaser');
$component = $display->getComponent('field_company');
$this->assertInternalType('array', $component);
$this->assertSame('entity_reference_label', $component['type']);
// The plain node reference formatter shows the referenced node's title,
// unlinked.
$this->assertFalse($component['settings']['link']);
}
}
......@@ -139,6 +139,17 @@ public function testFieldInstanceMigration() {
$expected = [];
$this->assertSame($expected, $field->getDefaultValueLiteral());
$this->assertTrue($field->isTranslatable());
// Test a node reference field, migrated to entity reference.
$field = FieldConfig::load('node.employee.field_company');
$this->assertInstanceOf(FieldConfig::class, $field);
$this->assertSame('entity_reference', $field->getType());
$this->assertSame('Company', $field->label());
$this->assertSame('default:node', $field->getSetting('handler'));
$this->assertSame([], $field->getSetting('handler_settings'));
$this->assertSame('node', $field->getSetting('target_type'));
$this->assertSame([], $field->getDefaultValueLiteral());
$this->assertTrue($field->isTranslatable());
}
/**
......
......@@ -27,40 +27,40 @@ public function testFields() {
// Text field.
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$field_storage = FieldStorageConfig::load('node.field_test');
$this->assertIdentical('text_long', $field_storage->getType());
$this->assertSame('text_long', $field_storage->getType());
// text_long fields do not have settings.
$this->assertIdentical([], $field_storage->getSettings());
$this->assertSame([], $field_storage->getSettings());
// Integer field.
$field_storage = FieldStorageConfig::load('node.field_test_two');
$this->assertIdentical("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', ['@fieldtype' => $field_storage->getType()]));
// Float field.
$field_storage = FieldStorageConfig::load('node.field_test_three');
$this->assertIdentical("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', ['@fieldtype' => $field_storage->getType()]));
// Link field.
$field_storage = FieldStorageConfig::load('node.field_test_link');
$this->assertIdentical("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', ['@fieldtype' => $field_storage->getType()]));
// File field.
$field_storage = FieldStorageConfig::load('node.field_test_filefield');
$this->assertIdentical("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', ['@fieldtype' => $field_storage->getType()]));
$field_storage = FieldStorageConfig::load('node.field_test_imagefield');
$this->assertIdentical("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', ['@fieldtype' => $field_storage->getType()]));
$settings = $field_storage->getSettings();
$this->assertIdentical('file', $settings['target_type']);
$this->assertIdentical('public', $settings['uri_scheme']);
$this->assertIdentical([], array_filter($settings['default_image']));
$this->assertSame('file', $settings['target_type']);
$this->assertSame('public', $settings['uri_scheme']);
$this->assertSame([], array_filter($settings['default_image']));
// Phone field.
$field_storage = FieldStorageConfig::load('node.field_test_phone');
$this->assertIdentical("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', ['@fieldtype' => $field_storage->getType()]));
// Date field.
$field_storage = FieldStorageConfig::load('node.field_test_datetime');
$this->assertIdentical("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()]));
// Date fields.
$field_storage = FieldStorageConfig::load('node.field_test_datetime');
......@@ -72,11 +72,11 @@ public function testFields() {
// Decimal field with radio buttons.
$field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons');
$this->assertIdentical("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', ['@fieldtype' => $field_storage->getType()]));
$this->assertNotNull($field_storage->getSetting('allowed_values')['1.2'], t('First allowed value key is set to 1.2'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value key is set to 2.1'));
$this->assertIdentical('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2'));
$this->assertIdentical('2.1', $field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value is set to 1.2'));
$this->assertSame('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2'));
$this->assertSame('2.1', $field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value is set to 1.2'));
// Email field.
$field_storage = FieldStorageConfig::load('node.field_test_email');
......@@ -84,36 +84,42 @@ public function testFields() {
// Float field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox');
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()]));
// Integer field with a select list.
$field_storage = FieldStorageConfig::load('node.field_test_integer_selectlist');
$this->assertIdentical("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', ['@fieldtype' => $field_storage->getType()]));
$this->assertNotNull($field_storage->getSetting('allowed_values')['1234'], t('First allowed value key is set to 1234'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['2341'], t('Second allowed value key is set to 2341'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['3412'], t('Third allowed value key is set to 3412'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value key is set to 4123'));
$this->assertIdentical('1234', $field_storage->getSetting('allowed_values')['1234'], t('First allowed value is set to 1234'));
$this->assertIdentical('2341', $field_storage->getSetting('allowed_values')['2341'], t('Second allowed value is set to 2341'));
$this->assertIdentical('3412', $field_storage->getSetting('allowed_values')['3412'], t('Third allowed value is set to 3412'));
$this->assertIdentical('4123', $field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value is set to 4123'));
$this->assertSame('1234', $field_storage->getSetting('allowed_values')['1234'], t('First allowed value is set to 1234'));
$this->assertSame('2341', $field_storage->getSetting('allowed_values')['2341'], t('Second allowed value is set to 2341'));
$this->assertSame('3412', $field_storage->getSetting('allowed_values')['3412'], t('Third allowed value is set to 3412'));
$this->assertSame('4123', $field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value is set to 4123'));
// Text field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox');
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()]));
$this->assertSame("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()]));
// Test a node reference field.
$field_storage = FieldStorageConfig::load('node.field_company');
$this->assertInstanceOf(FieldStorageConfig::class, $field_storage);
$this->assertSame('entity_reference', $field_storage->getType());
$this->assertSame('node', $field_storage->getSetting('target_type'));
// Validate that the source count and processed count match up.
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = $this->getMigration('d6_field');
$this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
$this->assertSame($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
// Check that we've reported on a conflict in widget_types.
$messages = [];
foreach ($migration->getIdMap()->getMessageIterator() as $message_row) {
$messages[] = $message_row->message;
}
$this->assertIdentical(count($messages), 1);
$this->assertIdentical($messages[0], 'Widget types optionwidgets_onoff, text_textfield are used in Drupal 6 field instances: widget type optionwidgets_onoff applied to the Drupal 8 base field');
$this->assertCount(1, $messages);
$this->assertSame($messages[0], 'Widget types optionwidgets_onoff, text_textfield are used in Drupal 6 field instances: widget type optionwidgets_onoff applied to the Drupal 8 base field');
}
}
......@@ -101,6 +101,11 @@ public function testWidgetSettings() {
$component = $form_display->getComponent('field_test_datetime');
$expected['weight'] = 12;
$this->assertIdentical($expected, $component);
$component = entity_get_form_display('node', 'employee', 'default')
->getComponent('field_company');
$this->assertInternalType('array', $component);
$this->assertSame('options_select', $component['type']);
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -44,14 +44,14 @@ protected function getEntityCounts() {
'contact_form' => 5,
'configurable_language' => 5,
'editor' => 2,
'field_config' => 71,
'field_storage_config' => 46,
'field_config' => 72,
'field_storage_config' => 47,
'file' => 7,
'filter_format' => 7,
'image_style' => 5,
'language_content_settings' => 2,
'migration' => 105,
'node' => 11,
'node' => 16,
'node_type' => 13,
'rdf_mapping' => 7,
'search_page' => 2,
......@@ -69,7 +69,7 @@ protected function getEntityCounts() {
'date_format' => 11,
'entity_form_display' => 19,
'entity_form_mode' => 1,
'entity_view_display' => 41,
'entity_view_display' => 43,
'entity_view_mode' => 14,
'base_field_override' => 38,
];
......
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