X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ftext%2Fsrc%2FPlugin%2Fmigrate%2Ffield%2Fd6%2FTextField.php;fp=web%2Fcore%2Fmodules%2Ftext%2Fsrc%2FPlugin%2Fmigrate%2Ffield%2Fd6%2FTextField.php;h=d1da3f43f4d4326c78cc7bc6ae9454b1d759d159;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/text/src/Plugin/migrate/field/d6/TextField.php b/web/core/modules/text/src/Plugin/migrate/field/d6/TextField.php new file mode 100644 index 000000000..d1da3f43f --- /dev/null +++ b/web/core/modules/text/src/Plugin/migrate/field/d6/TextField.php @@ -0,0 +1,131 @@ + 'text_textfield', + ]; + } + + /** + * {@inheritdoc} + */ + public function getFieldFormatterMap() { + return [ + 'default' => 'text_default', + 'trimmed' => 'text_trimmed', + 'plain' => 'basic_string', + ]; + } + + /** + * {@inheritdoc} + */ + public function processFieldValues(MigrationInterface $migration, $field_name, $field_info) { + $widget_type = isset($field_info['widget_type']) ? $field_info['widget_type'] : $field_info['widget']['type']; + + if ($widget_type == 'optionwidgets_onoff') { + $process = [ + 'value' => [ + 'plugin' => 'static_map', + 'source' => 'value', + 'default_value' => 0, + ], + ]; + + $checked_value = explode("\n", $field_info['global_settings']['allowed_values'])[1]; + if (strpos($checked_value, '|') !== FALSE) { + $checked_value = substr($checked_value, 0, strpos($checked_value, '|')); + } + $process['value']['map'][$checked_value] = 1; + } + else { + // See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(), + // signature_format for an example of the YAML that represents this + // process array. + $process = [ + 'value' => 'value', + 'format' => [ + [ + 'plugin' => 'static_map', + 'bypass' => TRUE, + 'source' => 'format', + 'map' => [0 => NULL], + ], + [ + 'plugin' => 'skip_on_empty', + 'method' => 'process', + ], + [ + 'plugin' => 'migration', + 'migration' => [ + 'd6_filter_format', + 'd7_filter_format', + ], + 'source' => 'format', + ], + ], + ]; + } + + $process = [ + 'plugin' => 'sub_process', + 'source' => $field_name, + 'process' => $process, + ]; + $migration->setProcessOfProperty($field_name, $process); + } + + /** + * {@inheritdoc} + */ + public function getFieldType(Row $row) { + $widget_type = $row->getSourceProperty('widget_type'); + $settings = $row->getSourceProperty('global_settings'); + + if ($widget_type == 'text_textfield') { + $field_type = $settings['text_processing'] ? 'text' : 'string'; + if (empty($settings['max_length']) || $settings['max_length'] > 255) { + $field_type .= '_long'; + } + return $field_type; + } + + if ($widget_type == 'text_textarea') { + $field_type = $settings['text_processing'] ? 'text_long' : 'string_long'; + return $field_type; + } + + switch ($widget_type) { + case 'optionwidgets_buttons': + case 'optionwidgets_select': + return 'list_string'; + case 'optionwidgets_onoff': + return 'boolean'; + default: + return parent::getFieldType($row); + } + } + +}