Version 1
[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    * {@inheritdoc}
24    */
25   public function processField(MigrationInterface $migration) {
26     $process[0]['map'][$this->pluginId][$this->pluginId] = $this->pluginId;
27     $migration->mergeProcessOfProperty('type', $process);
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function processFieldInstance(MigrationInterface $migration) {
34     // Nothing to do by default with field instances.
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function processFieldWidget(MigrationInterface $migration) {
41     $process = [];
42     foreach ($this->getFieldWidgetMap() as $source_widget => $destination_widget) {
43       $process['type']['map'][$source_widget] = $destination_widget;
44     }
45     $migration->mergeProcessOfProperty('options/type', $process);
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function getFieldWidgetMap() {
52     // By default, use the plugin ID for the widget types.
53     return [
54       $this->pluginId => $this->pluginId . '_default',
55     ];
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function processFieldFormatter(MigrationInterface $migration) {
62     $process = [];
63     foreach ($this->getFieldFormatterMap() as $source_format => $destination_format) {
64       $process[0]['map'][$this->pluginId][$source_format] = $destination_format;
65     }
66     $migration->mergeProcessOfProperty('options/type', $process);
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function getFieldType(Row $row) {
73     $field_type = $row->getSourceProperty('type');
74
75     if (isset($this->pluginDefinition['type_map'][$field_type])) {
76       return $this->pluginDefinition['type_map'][$field_type];
77     }
78     else {
79       return $field_type;
80     }
81   }
82
83 }