Skip to content
Snippets Groups Projects
Commit 3148d1c4 authored by catch's avatar catch
Browse files

Issue #2906203 by maxocub: Widgets/formatters: D7 Plain text fields...

Issue #2906203 by maxocub: Widgets/formatters: D7 Plain text fields incorrectly migrated to D8 as Text (formatted)
parent 73347e1c
No related branches found
No related tags found
No related merge requests found
......@@ -47,11 +47,15 @@ process:
"options/label": 'formatter/label'
"options/weight": 'formatter/weight'
# The formatter to use.
formatter_type:
plugin: process_field
source: type
method: getFieldFormatterType
"options/type":
-
plugin: static_map
bypass: true
source: 'formatter/type'
source: '@formatter_type'
map:
date_default: datetime_default
email_default: email_mailto
......
......@@ -31,11 +31,15 @@ process:
field_name: field_name
entity_type: entity_type
'options/weight': 'widget/weight'
widget_type:
plugin: process_field
source: type
method: getFieldWidgetType
'options/type':
type:
plugin: static_map
bypass: true
source: 'widget/type'
source: '@widget_type'
map:
link_field: link_default
email_textfield: email_default
......
......@@ -229,6 +229,11 @@ public function testMigration() {
$this->assertComponent('node.article.default', 'body', 'text_default', 'hidden', 0);
$this->assertComponent('node.article.default', 'field_tags', 'entity_reference_label', 'above', 10);
$this->assertComponent('node.article.default', 'field_image', 'image', 'hidden', -1);
$this->assertComponent('node.article.default', 'field_text_plain', 'string', 'above', 11);
$this->assertComponent('node.article.default', 'field_text_filtered', 'text_default', 'above', 12);
$this->assertComponent('node.article.default', 'field_text_long_plain', 'basic_string', 'above', 14);
$this->assertComponent('node.article.default', 'field_text_long_filtered', 'text_default', 'above', 15);
$this->assertComponent('node.article.default', 'field_text_sum_filtered', 'text_default', 'above', 18);
$this->assertEntity('node.article.teaser');
$this->assertComponent('node.article.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
......@@ -257,6 +262,11 @@ public function testMigration() {
$this->assertEntity('node.page.default');
$this->assertComponent('node.page.default', 'body', 'text_default', 'hidden', 0);
$this->assertComponent('node.page.default', 'field_text_plain', 'string', 'above', 1);
$this->assertComponent('node.page.default', 'field_text_filtered', 'text_default', 'above', 2);
$this->assertComponent('node.page.default', 'field_text_long_plain', 'basic_string', 'above', 4);
$this->assertComponent('node.page.default', 'field_text_long_filtered', 'text_default', 'above', 5);
$this->assertComponent('node.page.default', 'field_text_sum_filtered', 'text_default', 'above', 8);
$this->assertEntity('node.page.teaser');
$this->assertComponent('node.page.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
......
......@@ -96,11 +96,21 @@ protected function assertComponent($display_id, $component_id, $widget_type, $we
public function testWidgetSettings() {
$this->assertEntity('node.page.default', 'node', 'page');
$this->assertComponent('node.page.default', 'body', 'text_textarea_with_summary', -4);
$this->assertComponent('node.page.default', 'field_text_plain', 'string_textfield', -2);
$this->assertComponent('node.page.default', 'field_text_filtered', 'text_textfield', 0);
$this->assertComponent('node.page.default', 'field_text_long_plain', 'string_textarea', 4);
$this->assertComponent('node.page.default', 'field_text_long_filtered', 'text_textarea', 6);
$this->assertComponent('node.page.default', 'field_text_sum_filtered', 'text_textarea_with_summary', 12);
$this->assertEntity('node.article.default', 'node', 'article');
$this->assertComponent('node.article.default', 'body', 'text_textarea_with_summary', -4);
$this->assertComponent('node.article.default', 'field_tags', 'entity_reference_autocomplete', -4);
$this->assertComponent('node.article.default', 'field_image', 'image_image', -1);
$this->assertComponent('node.article.default', 'field_text_plain', 'string_textfield', 11);
$this->assertComponent('node.article.default', 'field_text_filtered', 'text_textfield', 12);
$this->assertComponent('node.article.default', 'field_text_long_plain', 'string_textarea', 14);
$this->assertComponent('node.article.default', 'field_text_long_filtered', 'text_textarea', 15);
$this->assertComponent('node.article.default', 'field_text_sum_filtered', 'text_textarea_with_summary', 18);
$this->assertEntity('node.blog.default', 'node', 'blog');
$this->assertComponent('node.blog.default', 'body', 'text_textarea_with_summary', -4);
......@@ -129,7 +139,7 @@ public function testWidgetSettings() {
$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', 'string_textfield', 15);
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'options_select', 11);
$this->assertEntity('user.user.default', 'user', 'user');
......
......@@ -43,6 +43,17 @@ public function processFieldWidget(MigrationInterface $migration);
*/
public function processFieldFormatter(MigrationInterface $migration);
/**
* Get the field formatter type from the source.
*
* @param \Drupal\migrate\Row $row
* The field being migrated.
*
* @return string
* The field formatter type.
*/
public function getFieldFormatterType(Row $row);
/**
* Get a map between D6 formatters and D8 formatters for this field type.
*
......@@ -53,6 +64,17 @@ public function processFieldFormatter(MigrationInterface $migration);
*/
public function getFieldFormatterMap();
/**
* Get the field widget type from the source.
*
* @param \Drupal\migrate\Row $row
* The field being migrated.
*
* @return string
* The field widget type.
*/
public function getFieldWidgetType(Row $row);
/**
* Get a map between D6 and D8 widgets for this field type.
*
......
......@@ -140,13 +140,13 @@ public function getProcess() {
$field_type = $row->getSourceProperty('type');
try {
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this);
$manager = $this->cckPluginManager;
$plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this);
$manager = $this->fieldPluginManager;
}
catch (PluginNotFoundException $ex) {
try {
$plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this);
$manager = $this->fieldPluginManager;
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this);
$manager = $this->cckPluginManager;
}
catch (PluginNotFoundException $ex) {
continue;
......
......@@ -45,6 +45,13 @@ public function processFieldWidget(MigrationInterface $migration) {
$migration->mergeProcessOfProperty('options/type', $process);
}
/**
* {@inheritdoc}
*/
public function getFieldFormatterType(Row $row) {
return $row->getSourceProperty('formatter/type');
}
/**
* {@inheritdoc}
*/
......@@ -52,6 +59,13 @@ public function getFieldFormatterMap() {
return [];
}
/**
* {@inheritdoc}
*/
public function getFieldWidgetType(Row $row) {
return $row->getSourceProperty('widget/type');
}
/**
* {@inheritdoc}
*/
......@@ -67,8 +81,13 @@ public function getFieldWidgetMap() {
*/
public function processFieldFormatter(MigrationInterface $migration) {
$process = [];
// Some migrate field plugin IDs are prefixed with 'd6_' or 'd7_'. Since the
// plugin ID is used in the static map as the module name, we have to remove
// this prefix from the plugin ID.
$plugin_id = preg_replace('/d[67]_/', '', $this->pluginId);
foreach ($this->getFieldFormatterMap() as $source_format => $destination_format) {
$process[0]['map'][$this->pluginId][$source_format] = $destination_format;
$process[0]['map'][$plugin_id][$source_format] = $destination_format;
}
$migration->mergeProcessOfProperty('options/type', $process);
}
......
......@@ -19,6 +19,44 @@
*/
class TextField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterType(Row $row) {
$field_type = $this->getFieldType($row);
$formatter_type = $row->getSourceProperty('formatter/type');
switch ($field_type) {
case 'string':
$formatter_type = str_replace('text_default', 'string', $formatter_type);
break;
case 'string_long':
$formatter_type = str_replace('text_default', 'basic_string', $formatter_type);
break;
}
return $formatter_type;
}
/**
* {@inheritdoc}
*/
public function getFieldWidgetType(Row $row) {
$field_type = $this->getFieldType($row);
$widget_type = $row->getSourceProperty('widget/type');
switch ($field_type) {
case 'string':
$widget_type = str_replace('text_textfield', 'string_textfield', $widget_type);
break;
case 'string_long':
$widget_type = str_replace('text_textarea', 'string_textarea', $widget_type);
break;
}
return $widget_type;
}
/**
* {@inheritdoc}
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment