Version 1
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / source / d7 / FieldInstancePerFormDisplay.php
1 <?php
2
3 namespace Drupal\field\Plugin\migrate\source\d7;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * The field instance per form display source class.
10  *
11  * @MigrateSource(
12  *   id = "d7_field_instance_per_form_display"
13  * )
14  */
15 class FieldInstancePerFormDisplay extends DrupalSqlBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function query() {
21     $query = $this->select('field_config_instance', 'fci')
22       ->fields('fci', [
23         'field_name',
24         'bundle',
25         'data',
26         'entity_type'
27       ])
28       ->fields('fc', [
29         'type',
30         'module',
31       ]);
32     $query->join('field_config', 'fc', 'fci.field_id = fc.id');
33     return $query;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function prepareRow(Row $row) {
40     $data = unserialize($row->getSourceProperty('data'));
41     $row->setSourceProperty('widget', $data['widget']);
42     $row->setSourceProperty('widget_settings', $data['widget']['settings']);
43     return parent::prepareRow($row);
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function fields() {
50     return [
51       'field_name' => $this->t('The machine name of field.'),
52       'bundle' => $this->t('Content type where this field is used.'),
53       'data' => $this->t('Field configuration data.'),
54       'entity_type' => $this->t('The entity type.'),
55     ];
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function getIds() {
62     return [
63       'bundle' => [
64         'type' => 'string',
65       ],
66       'field_name' => [
67         'type' => 'string',
68         'alias' => 'fci',
69       ],
70     ];
71   }
72
73 }