3 namespace Drupal\migrate_drupal\Plugin\migrate\field;
5 use Drupal\Core\Plugin\PluginBase;
6 use Drupal\migrate\Plugin\MigrationInterface;
7 use Drupal\migrate\Row;
8 use Drupal\migrate_drupal\Plugin\MigrateFieldInterface;
11 * The base class for all field plugins.
13 * @see \Drupal\migrate\Plugin\MigratePluginManager
14 * @see \Drupal\migrate_drupal\Annotation\MigrateField
15 * @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
20 abstract class FieldPluginBase extends PluginBase implements MigrateFieldInterface {
25 public function processField(MigrationInterface $migration) {
26 $process[0]['map'][$this->pluginId][$this->pluginId] = $this->pluginId;
27 $migration->mergeProcessOfProperty('type', $process);
33 public function processFieldInstance(MigrationInterface $migration) {
34 // Nothing to do by default with field instances.
40 public function processFieldWidget(MigrationInterface $migration) {
42 foreach ($this->getFieldWidgetMap() as $source_widget => $destination_widget) {
43 $process['type']['map'][$source_widget] = $destination_widget;
45 $migration->mergeProcessOfProperty('options/type', $process);
51 public function getFieldFormatterType(Row $row) {
52 return $row->getSourceProperty('formatter/type');
58 public function getFieldFormatterMap() {
65 public function getFieldWidgetType(Row $row) {
66 return $row->getSourceProperty('widget/type');
72 public function getFieldWidgetMap() {
73 // By default, use the plugin ID for the widget types.
75 $this->pluginId => $this->pluginId . '_default',
82 public function processFieldFormatter(MigrationInterface $migration) {
85 // Some migrate field plugin IDs are prefixed with 'd6_' or 'd7_'. Since the
86 // plugin ID is used in the static map as the module name, we have to remove
87 // this prefix from the plugin ID.
88 $plugin_id = preg_replace('/d[67]_/', '', $this->pluginId);
89 foreach ($this->getFieldFormatterMap() as $source_format => $destination_format) {
90 $process[0]['map'][$plugin_id][$source_format] = $destination_format;
92 $migration->mergeProcessOfProperty('options/type', $process);
98 public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
101 'source' => $field_name,
103 $migration->mergeProcessOfProperty($field_name, $process);
109 public function getFieldType(Row $row) {
110 $field_type = $row->getSourceProperty('type');
112 if (isset($this->pluginDefinition['type_map'][$field_type])) {
113 return $this->pluginDefinition['type_map'][$field_type];