7339e764a889334b7a36d0ceb3560b581f115cb3
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / source / d7 / FieldInstancePerViewMode.php
1 <?php
2
3 namespace Drupal\field\Plugin\migrate\source\d7;
4
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6
7 /**
8  * The field instance per view mode source class.
9  *
10  * @MigrateSource(
11  *   id = "d7_field_instance_per_view_mode",
12  *   source_provider = "field"
13  * )
14  */
15 class FieldInstancePerViewMode extends DrupalSqlBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function initializeIterator() {
21     $rows = [];
22     $result = $this->prepareQuery()->execute();
23     foreach ($result as $field_instance) {
24       $data = unserialize($field_instance['data']);
25       // We don't need to include the serialized data in the returned rows.
26       unset($field_instance['data']);
27
28       foreach ($data['display'] as $view_mode => $info) {
29         // Rename type to formatter_type in the info array.
30         $info['formatter_type'] = $info['type'];
31         unset($info['type']);
32
33         $rows[] = array_merge($field_instance, $info, [
34           'view_mode' => $view_mode,
35         ]);
36       }
37     }
38     return new \ArrayIterator($rows);
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function query() {
45     $query = $this->select('field_config_instance', 'fci')
46       ->fields('fci', ['entity_type', 'bundle', 'field_name', 'data'])
47       ->fields('fc', ['type']);
48     $query->join('field_config', 'fc', 'fc.field_name = fci.field_name');
49     return $query;
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function fields() {
56     return [
57       'entity_type' => $this->t('The entity type ID.'),
58       'bundle' => $this->t('The bundle ID.'),
59       'field_name' => $this->t('Machine name of the field.'),
60       'view_mode' => $this->t('The original machine name of the view mode.'),
61       'label' => $this->t('The display label of the field.'),
62       'type' => $this->t('The field ID.'),
63       'formatter_type' => $this->t('The formatter ID.'),
64       'settings' => $this->t('Array of formatter-specific settings.'),
65       'module' => $this->t('The module providing the formatter.'),
66       'weight' => $this->t('Display weight of the field.'),
67     ];
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function getIds() {
74     return [
75       'entity_type' => [
76         'type' => 'string',
77       ],
78       'bundle' => [
79         'type' => 'string',
80       ],
81       'view_mode' => [
82         'type' => 'string',
83       ],
84       'field_name' => [
85         'type' => 'string',
86       ],
87     ];
88   }
89
90   /**
91    * {@inheritdoc}
92    */
93   public function count() {
94     return $this->initializeIterator()->count();
95   }
96
97 }