3 namespace Drupal\text\Plugin\migrate\field\d7;
5 use Drupal\migrate\Row;
6 use Drupal\migrate\MigrateSkipRowException;
7 use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
14 * "text_long" = "text_long",
15 * "text_with_summary" = "text_with_summary"
18 * source_module = "text",
19 * destination_module = "text",
22 class TextField extends FieldPluginBase {
27 public function getFieldFormatterType(Row $row) {
28 $field_type = $this->getFieldType($row);
29 $formatter_type = $row->getSourceProperty('formatter/type');
31 switch ($field_type) {
33 $formatter_type = str_replace('text_default', 'string', $formatter_type);
36 $formatter_type = str_replace('text_default', 'basic_string', $formatter_type);
40 return $formatter_type;
46 public function getFieldWidgetType(Row $row) {
47 $field_type = $this->getFieldType($row);
48 $widget_type = $row->getSourceProperty('widget/type');
50 switch ($field_type) {
52 $widget_type = str_replace('text_textfield', 'string_textfield', $widget_type);
55 $widget_type = str_replace('text_textarea', 'string_textarea', $widget_type);
65 public function getFieldType(Row $row) {
66 $type = $row->getSourceProperty('type');
68 $filtered_text = FALSE;
70 foreach ($row->getSourceProperty('instances') as $instance) {
71 // Check if this field has plain text instances, filtered text instances,
73 $data = unserialize($instance['data']);
74 switch ($data['settings']['text_processing']) {
79 $filtered_text = TRUE;
84 if (in_array($type, ['text', 'text_long'])) {
85 // If a text or text_long field has only plain text instances, migrate it
86 // to a string or string_long field.
87 if ($plain_text && !$filtered_text) {
88 $type = str_replace(['text', 'text_long'], ['string', 'string_long'], $type);
90 // If a text or text_long field has both plain text and filtered text
91 // instances, skip the row.
92 elseif ($plain_text && $filtered_text) {
93 $field_name = $row->getSourceProperty('field_name');
94 throw new MigrateSkipRowException("Can't migrate source field $field_name configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
97 elseif ($type == 'text_with_summary' && $plain_text) {
98 // If a text_with_summary field has plain text instances, skip the row
99 // since there's no such thing as a string_with_summary field.
100 $field_name = $row->getSourceProperty('field_name');
101 throw new MigrateSkipRowException("Can't migrate source field $field_name of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");