3dd037c9bf716d0bff77e29d8c2704e8fd344e95
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / source / d7 / ViewMode.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  * @MigrateSource(
9  *  id = "d7_view_mode"
10  * )
11  */
12 class ViewMode extends DrupalSqlBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function initializeIterator() {
18     $rows = [];
19     $result = $this->prepareQuery()->execute();
20     foreach ($result as $field_instance) {
21       $data = unserialize($field_instance['data']);
22       foreach (array_keys($data['display']) as $view_mode) {
23         $key = $field_instance['entity_type'] . '.' . $view_mode;
24         $rows[$key] = [
25           'entity_type' => $field_instance['entity_type'],
26           'view_mode' => $view_mode,
27         ];
28       }
29     }
30     return new \ArrayIterator($rows);
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function fields() {
37     return [
38       'view_mode' => $this->t('The view mode ID.'),
39       'entity_type' => $this->t('The entity type ID.'),
40     ];
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function query() {
47     return $this->select('field_config_instance', 'fci')
48       ->fields('fci', ['entity_type', 'data']);
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getIds() {
55     return [
56       'entity_type' => [
57         'type' => 'string',
58       ],
59       'view_mode' => [
60         'type' => 'string',
61       ],
62     ];
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function count() {
69     return $this->initializeIterator()->count();
70   }
71
72 }