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 {
23 * Alters the migration for field definitions.
25 * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
26 * alterFieldMigration() instead.
28 * @see https://www.drupal.org/node/2944598
29 * @see ::alterFieldMigration()
31 public function processField(MigrationInterface $migration) {
32 @trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldMigration() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
33 $this->alterFieldMigration($migration);
39 public function alterFieldMigration(MigrationInterface $migration) {
40 $process[0]['map'][$this->pluginId][$this->pluginId] = $this->pluginId;
41 $migration->mergeProcessOfProperty('type', $process);
45 * Alert field instance migration.
47 * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
48 * alterFieldInstanceMigration() instead.
50 * @see https://www.drupal.org/node/2944598
51 * @see ::alterFieldInstanceMigration()
53 public function processFieldInstance(MigrationInterface $migration) {
54 @trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldInstanceMigration() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
55 $this->alterFieldInstanceMigration($migration);
61 public function alterFieldInstanceMigration(MigrationInterface $migration) {
62 // Nothing to do by default with field instances.
66 * Alter field widget migration.
68 * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
69 * alterFieldWidgetMigration() instead.
71 * @see https://www.drupal.org/node/2944598
72 * @see ::alterFieldWidgetMigration()
74 public function processFieldWidget(MigrationInterface $migration) {
75 @trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldWidgetMigration() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
76 $this->alterFieldWidgetMigration($migration);
82 public function alterFieldWidgetMigration(MigrationInterface $migration) {
84 foreach ($this->getFieldWidgetMap() as $source_widget => $destination_widget) {
85 $process['type']['map'][$source_widget] = $destination_widget;
87 $migration->mergeProcessOfProperty('options/type', $process);
93 public function getFieldFormatterType(Row $row) {
94 return $row->getSourceProperty('formatter/type');
100 public function getFieldFormatterMap() {
107 public function getFieldWidgetType(Row $row) {
108 return $row->getSourceProperty('widget/type');
114 public function getFieldWidgetMap() {
115 // By default, use the plugin ID for the widget types.
117 $this->pluginId => $this->pluginId . '_default',
122 * Alter field formatter migration.
124 * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
125 * alterFieldFormatterMigration() instead.
127 * @see https://www.drupal.org/node/2944598
128 * @see ::processFieldFormatter()
130 public function processFieldFormatter(MigrationInterface $migration) {
131 @trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldFormatterMigration() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
132 $this->alterFieldFormatterMigration($migration);
138 public function alterFieldFormatterMigration(MigrationInterface $migration) {
140 // Some migrate field plugin IDs are prefixed with 'd6_' or 'd7_'. Since the
141 // plugin ID is used in the static map as the module name, we have to remove
142 // this prefix from the plugin ID.
143 $plugin_id = preg_replace('/d[67]_/', '', $this->pluginId);
144 foreach ($this->getFieldFormatterMap() as $source_format => $destination_format) {
145 $process[0]['map'][$plugin_id][$source_format] = $destination_format;
147 $migration->mergeProcessOfProperty('options/type', $process);
151 * Defines the process pipeline for field values.
153 * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
154 * defineValueProcessPipeline() instead.
156 * @see https://www.drupal.org/node/2944598
157 * @see ::defineValueProcessPipeline()
159 public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
160 @trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
161 return $this->defineValueProcessPipeline($migration, $field_name, $data);
167 public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
170 'source' => $field_name,
172 $migration->mergeProcessOfProperty($field_name, $process);
178 public function getFieldType(Row $row) {
179 $field_type = $row->getSourceProperty('type');
181 if (isset($this->pluginDefinition['type_map'][$field_type])) {
182 return $this->pluginDefinition['type_map'][$field_type];