diff --git a/core/modules/field/migration_templates/d7_field_formatter_settings.yml b/core/modules/field/migration_templates/d7_field_formatter_settings.yml index 2c0196b611068dc72db96b304784c9fc5db7783a..4d48d138059f7babcd55912232cd877ea69b123e 100644 --- a/core/modules/field/migration_templates/d7_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d7_field_formatter_settings.yml @@ -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 diff --git a/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml b/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml index 986e02ce514dad7c1e4dbbc3d7a5e75b9d776f4e..9578d38896668834406a86fc338aba894ed43bf4 100644 --- a/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml +++ b/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml @@ -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 diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php index dd38569de144ebcf19bbfbb7093bd6056f7d96d3..31077fd8ca90eafd2595c758d5836c7c961f50be 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php @@ -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); diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php index 994140d064838f7d7b942f3851950540ab61442d..ee4d204af35ba4f9cc9997663a07fc3a20d155c0 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php @@ -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'); diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php index c8cecad3338c6b75fdab23e0324274a6587aea2b..2aac5d18eb36a81c0acaa5c095725d722d77b76f 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php @@ -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. * diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/FieldMigration.php b/core/modules/migrate_drupal/src/Plugin/migrate/FieldMigration.php index 9222e57c343219fe27e05eb90278ea3e6f18dc2a..3ca8f26a8bbe88588bff99a8e00ae69d09cd6c3c 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/FieldMigration.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/FieldMigration.php @@ -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; diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/field/FieldPluginBase.php b/core/modules/migrate_drupal/src/Plugin/migrate/field/FieldPluginBase.php index 027276c339f3c4d27c6c1d3771cef8140adb8dba..dc115abc99f6dd87dd8974e489f95ffa5dbc2b50 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/field/FieldPluginBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/FieldPluginBase.php @@ -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); } diff --git a/core/modules/text/src/Plugin/migrate/field/d7/TextField.php b/core/modules/text/src/Plugin/migrate/field/d7/TextField.php index c3d24c2119cc753b7a2a357cdd9ae6b08a5e2d59..ccdedd427a026cccd50bbc7646314e67f37ba837 100644 --- a/core/modules/text/src/Plugin/migrate/field/d7/TextField.php +++ b/core/modules/text/src/Plugin/migrate/field/d7/TextField.php @@ -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} */