Newer
Older
<?php
namespace Drupal\text\Plugin\migrate\field\d7;
use Drupal\migrate\Row;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateField(
* id = "d7_text",
* type_map = {
* "text" = "text",
* "text_long" = "text_long",
* "text_with_summary" = "text_with_summary"
* },
* core = {7},
* source_module = "text",
* destination_module = "text",
* )
*/
class TextField extends FieldPluginBase {
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* {@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;
}
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* {@inheritdoc}
*/
public function getFieldType(Row $row) {
$type = $row->getSourceProperty('type');
$plain_text = FALSE;
$filtered_text = FALSE;
foreach ($row->getSourceProperty('instances') as $instance) {
// Check if this field has plain text instances, filtered text instances,
// or both.
$data = unserialize($instance['data']);
switch ($data['settings']['text_processing']) {
case '0':
$plain_text = TRUE;
break;
case '1':
$filtered_text = TRUE;
break;
}
}
if (in_array($type, ['text', 'text_long'])) {
// If a text or text_long field has only plain text instances, migrate it
// to a string or string_long field.
if ($plain_text && !$filtered_text) {
$type = str_replace(['text', 'text_long'], ['string', 'string_long'], $type);
}
// If a text or text_long field has both plain text and filtered text
// instances, skip the row.
elseif ($plain_text && $filtered_text) {
$field_name = $row->getSourceProperty('field_name');
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");
}
}
elseif ($type == 'text_with_summary' && $plain_text) {
// If a text_with_summary field has plain text instances, skip the row
// since there's no such thing as a string_with_summary field.
$field_name = $row->getSourceProperty('field_name');
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");
}
return $type;
}
}