039960a4ed5b9ef1dd4533b9afd6922da1935a45
[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 /**
6  * The view mode source class.
7  *
8  * @MigrateSource(
9  *   id = "d7_view_mode",
10  *   source_module = "field"
11  * )
12  */
13 class ViewMode extends FieldInstance {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function initializeIterator() {
19     $instances = parent::initializeIterator();
20
21     $rows = [];
22     foreach ($instances->getArrayCopy() as $instance) {
23       $data = unserialize($instance['data']);
24       foreach (array_keys($data['display']) as $view_mode) {
25         $key = $instance['entity_type'] . '.' . $view_mode;
26         $rows[$key] = array_merge($instance, [
27           'view_mode' => $view_mode,
28         ]);
29       }
30     }
31
32     return new \ArrayIterator($rows);
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function fields() {
39     return array_merge(parent::fields(), [
40       'view_mode' => $this->t('The view mode ID.'),
41     ]);
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getIds() {
48     return [
49       'entity_type' => [
50         'type' => 'string',
51       ],
52       'view_mode' => [
53         'type' => 'string',
54       ],
55     ];
56   }
57
58 }