Commit 4f4904db authored by catch's avatar catch

Issue #2611066 by hussainweb, svendecabooter, brunodbo, generalredneck,...

Issue #2611066 by hussainweb, svendecabooter, brunodbo, generalredneck, iMiksu, joelpittet: Migration path to entity reference field from 7.x
parent fee4c4e2
......@@ -22,6 +22,7 @@ process:
datestamp: datetime
datetime: datetime
email: email
entityreference: entity_reference
file: file
image: image
link_field: link
......
......@@ -61,6 +61,9 @@ process:
link_default: link
phone: basic_string
taxonomy_term_reference_link: entity_reference_label
entityreference_label: entity_reference_label
entityreference_entity_id: entity_reference_entity_id
entityreference_entity_view: entity_reference_entity_view
-
plugin: skip_on_empty
method: row
......
......@@ -21,6 +21,7 @@ process:
source:
- instance_settings
- widget_settings
- field_settings
default_value_function: ''
default_value:
plugin: d7_field_instance_defaults
......
......@@ -46,6 +46,7 @@ process:
phone_textfield: telephone_default
options_onoff: boolean_checkbox
entityreference_autocomplete: entity_reference_autocomplete
entityreference_autocomplete_tags: entity_reference_autocomplete_tags
taxonomy_autocomplete: entity_reference_autocomplete
'options/settings':
plugin: field_instance_widget_settings
......
......@@ -17,9 +17,38 @@ class FieldInstanceSettings extends ProcessPluginBase {
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($instance_settings, $widget_settings) = $value;
list($instance_settings, $widget_settings, $field_settings) = $value;
$widget_type = $widget_settings['type'];
// Get entityreference handler settings from source field configuration.
if ($row->getSourceProperty('type') == "entityreference") {
$instance_settings['handler'] = 'default:' . $field_settings['target_type'];
// Transform the sort settings to D8 structure.
$sort = [
'field' => '_none',
'direction' => 'ASC',
];
if (!empty(array_filter($field_settings['handler_settings']['sort']))) {
if ($field_settings['handler_settings']['sort']['type'] == "property") {
$sort = [
'field' => $field_settings['handler_settings']['sort']['property'],
'direction' => $field_settings['handler_settings']['sort']['direction'],
];
}
elseif ($field_settings['handler_settings']['sort']['type'] == "field") {
$sort = [
'field' => $field_settings['handler_settings']['sort']['field'],
'direction' => $field_settings['handler_settings']['sort']['direction'],
];
}
}
if (empty($field_settings['handler_settings']['target_bundles'])) {
$field_settings['handler_settings']['target_bundles'] = NULL;
}
$field_settings['handler_settings']['sort'] = $sort;
$instance_settings['handler_settings'] = $field_settings['handler_settings'];
}
switch ($widget_type) {
case 'image_image':
$settings = $instance_settings;
......
......@@ -28,6 +28,7 @@ public function query() {
->fields('fc', array('type'));
$query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id');
$query->addField('fc', 'data', 'field_data');
// Optionally filter by entity type and bundle.
if (isset($this->configuration['entity_type'])) {
......@@ -53,6 +54,7 @@ public function fields() {
'instance_settings' => $this->t('Field instance settings.'),
'widget_settings' => $this->t('Widget settings.'),
'display_settings' => $this->t('Display settings.'),
'field_settings' => $this->t('Field settings.'),
);
}
......@@ -81,6 +83,9 @@ public function prepareRow(Row $row) {
// This is for parity with the d6_field_instance plugin.
$row->setSourceProperty('widget_type', $data['widget']['type']);
$field_data = unserialize($row->getSourceProperty('field_data'));
$row->setSourceProperty('field_settings', $field_data['settings']);
return parent::prepareRow($row);
}
......
......@@ -276,6 +276,9 @@ public function testMigration() {
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'list_default', 'above', 10);
$this->assertComponent('node.test_content_type.default', 'field_integer_list', 'list_default', 'above', 11);
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_default', 'above', 12);
$this->assertComponent('node.test_content_type.default', 'field_node_entityreference', 'entity_reference_label', 'above', 15);
$this->assertComponent('node.test_content_type.default', 'field_user_entityreference', 'entity_reference_label', 'above', 16);
$this->assertComponent('node.test_content_type.default', 'field_term_entityreference', 'entity_reference_label', 'above', 17);
$this->assertComponentNotExists('node.test_content_type.default', 'field_term_reference');
$this->assertComponentNotExists('node.test_content_type.default', 'field_text');
......
......@@ -141,6 +141,9 @@ public function testFieldInstances() {
$this->assertEntity('node.test_content_type.field_integer_list', 'Integer List', 'list_integer', FALSE);
$this->assertEntity('node.test_content_type.field_long_text', 'Long text', 'text_with_summary', FALSE);
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE);
$this->assertEntity('node.test_content_type.field_node_entityreference', 'Node Entity Reference', 'entity_reference', FALSE);
$this->assertEntity('node.test_content_type.field_user_entityreference', 'User Entity Reference', 'entity_reference', FALSE);
$this->assertEntity('node.test_content_type.field_term_entityreference', 'Term Entity Reference', 'entity_reference', FALSE);
$this->assertEntity('node.test_content_type.field_text', 'Text', 'text', FALSE);
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE);
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE);
......
......@@ -125,6 +125,9 @@ public function testWidgetSettings() {
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_textarea_with_summary', 13);
$this->assertComponent('node.test_content_type.default', 'field_phone', 'telephone_default', 6);
$this->assertComponent('node.test_content_type.default', 'field_term_reference', 'entity_reference_autocomplete', 14);
$this->assertComponent('node.test_content_type.default', 'field_node_entityreference', 'entity_reference_autocomplete', 16);
$this->assertComponent('node.test_content_type.default', 'field_user_entityreference', 'options_buttons', 17);
$this->assertComponent('node.test_content_type.default', 'field_term_entityreference', 'entity_reference_autocomplete_tags', 18);
$this->assertComponent('node.test_content_type.default', 'field_text', 'text_textfield', 15);
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'options_select', 11);
......
......@@ -100,6 +100,9 @@ public function testFields() {
$this->assertEntity('node.field_phone', 'telephone', FALSE, 1);
$this->assertEntity('node.field_date', 'datetime', FALSE, 1);
$this->assertEntity('node.field_date_with_end_time', 'datetime', FALSE, 1);
$this->assertEntity('node.field_node_entityreference', 'entity_reference', FALSE, -1);
$this->assertEntity('node.field_user_entityreference', 'entity_reference', FALSE, 1);
$this->assertEntity('node.field_term_entityreference', 'entity_reference', FALSE, -1);
// Assert that the taxonomy term reference fields are referencing the
// correct entity type.
......@@ -108,6 +111,15 @@ public function testFields() {
$field = FieldStorageConfig::load('node.taxonomy_forums');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
// Assert that the entityreference fields are referencing the correct
// entity type.
$field = FieldStorageConfig::load('node.field_node_entityreference');
$this->assertIdentical('node', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_user_entityreference');
$this->assertIdentical('user', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_term_entityreference');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
// Validate that the source count and processed count match up.
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = $this->getMigration('d7_field');
......
......@@ -28,7 +28,7 @@ public function testTransformImageSettings() {
->disableOriginalConstructor()
->getMock();
$value = $plugin->transform([[], ['type' => 'image_image']], $executable, $row, 'foo');
$value = $plugin->transform([[], ['type' => 'image_image'], []], $executable, $row, 'foo');
$this->assertInternalType('array', $value['default_image']);
$this->assertSame('', $value['default_image']['alt']);
$this->assertSame('', $value['default_image']['title']);
......
......@@ -43,8 +43,8 @@ protected function getEntityCounts() {
'configurable_language' => 4,
'contact_form' => 3,
'editor' => 2,
'field_config' => 45,
'field_storage_config' => 33,
'field_config' => 48,
'field_storage_config' => 36,
'file' => 1,
'filter_format' => 7,
'image_style' => 6,
......
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