Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / migrate_drupal / src / Plugin / migrate / field / FieldPluginBase.php
1 <?php
2
3 namespace Drupal\migrate_drupal\Plugin\migrate\field;
4
5 use Drupal\Core\Plugin\PluginBase;
6 use Drupal\migrate\Plugin\MigrationInterface;
7 use Drupal\migrate\Row;
8 use Drupal\migrate_drupal\Plugin\MigrateFieldInterface;
9
10 /**
11  * The base class for all field plugins.
12  *
13  * @see \Drupal\migrate\Plugin\MigratePluginManager
14  * @see \Drupal\migrate_drupal\Annotation\MigrateField
15  * @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
16  * @see plugin_api
17  *
18  * @ingroup migration
19  */
20 abstract class FieldPluginBase extends PluginBase implements MigrateFieldInterface {
21
22   /**
23    * Alters the migration for field definitions.
24    *
25    * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
26    *   alterFieldMigration() instead.
27    *
28    * @see https://www.drupal.org/node/2944598
29    * @see ::alterFieldMigration()
30    */
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);
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function alterFieldMigration(MigrationInterface $migration) {
40     $process[0]['map'][$this->pluginId][$this->pluginId] = $this->pluginId;
41     $migration->mergeProcessOfProperty('type', $process);
42   }
43
44   /**
45    * Alert field instance migration.
46    *
47    * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
48    *   alterFieldInstanceMigration() instead.
49    *
50    * @see https://www.drupal.org/node/2944598
51    * @see ::alterFieldInstanceMigration()
52    */
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);
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function alterFieldInstanceMigration(MigrationInterface $migration) {
62     // Nothing to do by default with field instances.
63   }
64
65   /**
66    * Alter field widget migration.
67    *
68    * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
69    *   alterFieldWidgetMigration() instead.
70    *
71    * @see https://www.drupal.org/node/2944598
72    * @see ::alterFieldWidgetMigration()
73    */
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);
77   }
78
79   /**
80    * {@inheritdoc}
81    */
82   public function alterFieldWidgetMigration(MigrationInterface $migration) {
83     $process = [];
84     foreach ($this->getFieldWidgetMap() as $source_widget => $destination_widget) {
85       $process['type']['map'][$source_widget] = $destination_widget;
86     }
87     $migration->mergeProcessOfProperty('options/type', $process);
88   }
89
90   /**
91    * {@inheritdoc}
92    */
93   public function getFieldFormatterType(Row $row) {
94     return $row->getSourceProperty('formatter/type');
95   }
96
97   /**
98    * {@inheritdoc}
99    */
100   public function getFieldFormatterMap() {
101     return [];
102   }
103
104   /**
105    * {@inheritdoc}
106    */
107   public function getFieldWidgetType(Row $row) {
108     return $row->getSourceProperty('widget/type');
109   }
110
111   /**
112    * {@inheritdoc}
113    */
114   public function getFieldWidgetMap() {
115     // By default, use the plugin ID for the widget types.
116     return [
117       $this->pluginId => $this->pluginId . '_default',
118     ];
119   }
120
121   /**
122    * Alter field formatter migration.
123    *
124    * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
125    *   alterFieldFormatterMigration() instead.
126    *
127    * @see https://www.drupal.org/node/2944598
128    * @see ::processFieldFormatter()
129    */
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);
133   }
134
135   /**
136    * {@inheritdoc}
137    */
138   public function alterFieldFormatterMigration(MigrationInterface $migration) {
139     $process = [];
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;
146     }
147     $migration->mergeProcessOfProperty('options/type', $process);
148   }
149
150   /**
151    * Defines the process pipeline for field values.
152    *
153    * @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
154    *   defineValueProcessPipeline() instead.
155    *
156    * @see https://www.drupal.org/node/2944598
157    * @see ::defineValueProcessPipeline()
158    */
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);
162   }
163
164   /**
165    * {@inheritdoc}
166    */
167   public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
168     $process = [
169       'plugin' => 'get',
170       'source' => $field_name,
171     ];
172     $migration->mergeProcessOfProperty($field_name, $process);
173   }
174
175   /**
176    * {@inheritdoc}
177    */
178   public function getFieldType(Row $row) {
179     $field_type = $row->getSourceProperty('type');
180
181     if (isset($this->pluginDefinition['type_map'][$field_type])) {
182       return $this->pluginDefinition['type_map'][$field_type];
183     }
184     else {
185       return $field_type;
186     }
187   }
188
189 }