diff --git a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php b/core/modules/text/src/Plugin/migrate/cckfield/TextField.php index 89475ff..9c3c2c6 100644 --- a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php +++ b/core/modules/text/src/Plugin/migrate/cckfield/TextField.php @@ -96,31 +96,67 @@ public function processCckFieldValues(MigrationInterface $migration, $field_name } /** - * {@inheritdoc} + * Computes the destination type of a migrated field. + * + * Text processing is defined in field storage settings in D6 so it's + * possible to migrate plain text as Text (plain) and filtered text + * as Text (formatted). In D7, the text processing is defined in field + * instance settings. D7 text fields are migrated as Text (plain). + * + * @see https://www.drupal.org/node/2842222 + * + * @param \Drupal\migrate\Row $row + * The field being migrated. + * + * @return string + * The destination field type. */ public function getFieldType(Row $row) { + // Drupal 7. + if ($row->getSourceProperty('key') == 'drupal_7') { + + // Text fields: Migrate as Text (plain) or Text (plain, long). + if ($row->getSourceProperty('type') == 'text') { + $field_type = 'string'; + $settings = $row->getSourceProperty('settings'); + if (empty($settings['max_length']) || $settings['max_length'] > 255) { + $field_type .= '_long'; + } + return $field_type; + } + + // All other types: keep the original type. + return parent::getFieldType($row); + } + + // Drupal 6. $widget_type = $row->getSourceProperty('widget_type'); + $settings = $row->getSourceProperty('global_settings'); + // Text fields: Check processing settings and field length. if ($widget_type == 'text_textfield') { - $settings = $row->getSourceProperty('global_settings'); $field_type = $settings['text_processing'] ? 'text' : 'string'; if (empty($settings['max_length']) || $settings['max_length'] > 255) { $field_type .= '_long'; } return $field_type; } - else { - switch ($widget_type) { - case 'optionwidgets_buttons': - case 'optionwidgets_select': - return 'list_string'; - case 'optionwidgets_onoff': - return 'boolean'; - case 'text_textarea': - return 'text_long'; - default: - return parent::getFieldType($row); - } + + // Text areas: Check processing settings. + if ($widget_type == 'text_textarea') { + $field_type = $settings['text_processing'] ? 'text_long' : 'string_long'; + return $field_type; + } + + // All other widget types. + switch ($widget_type) { + case 'optionwidgets_buttons': + case 'optionwidgets_select': + return 'list_string'; + case 'optionwidgets_onoff': + return 'boolean'; + default: + return parent::getFieldType($row); } } diff --git a/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php b/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php index 323fbce..c05a1fb 100644 --- a/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php +++ b/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php @@ -118,9 +118,9 @@ public function testProcessBooleanTextExplicitValues() { } /** - * Data provider for testGetFieldType(). + * Data provider for testGetFieldTypeD6(). */ - public function getFieldTypeProvider() { + public function getFieldTypeProviderD6() { return array( array('string_long', 'text_textfield', array( 'text_processing' => FALSE, @@ -147,19 +147,67 @@ public function getFieldTypeProvider() { array('list_string', 'optionwidgets_buttons'), array('list_string', 'optionwidgets_select'), array('boolean', 'optionwidgets_onoff'), - array('text_long', 'text_textarea'), + array('text_long', 'text_textarea', array( + 'text_processing' => TRUE, + )), + array('string_long', 'text_textarea', array( + 'text_processing' => FALSE, + )), array(NULL, 'undefined'), ); } /** * @covers ::getFieldType - * @dataProvider getFieldTypeProvider + * @dataProvider getFieldTypeProviderD6 */ - public function testGetFieldType($expected_type, $widget_type, array $settings = array()) { - $row = new Row(array('widget_type' => $widget_type), array('widget_type' => array())); + public function testGetFieldTypeD6($expected_type, $widget_type, array $settings = array()) { + $row = new Row(); + $row->setSourceProperty('widget_type', $widget_type); $row->setSourceProperty('global_settings', $settings); $this->assertSame($expected_type, $this->plugin->getFieldType($row)); } + /** + * Data provider for testGetFieldTypeD7(). + */ + public function getFieldTypeProviderD7() { + return array( + array( + 'string', + 'text', + array('max_length' => 128), + ), + array( + 'string_long', + 'text', + array('max_length' => 4096), + ), + array( + 'string_long', + 'text', + ), + array( + 'text_long', + 'text_long', + ), + array( + 'text_with_summary', + 'text_with_summary', + ), + ); + } + + /** + * @covers ::getFieldType + * @dataProvider getFieldTypeProviderD7 + */ + public function testGetFieldTypeD7($expected_type, $type, array $settings = array()) { + $row = new Row(); + $row->setSourceProperty('key', 'drupal_7'); + $row->setSourceProperty('type', $type); + $row->setSourceProperty('settings', $settings); + $this->assertSame($expected_type, $this->plugin->getFieldType($row)); + } + }