Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / node / src / Plugin / migrate / source / d6 / ViewMode.php
1 <?php
2
3 namespace Drupal\node\Plugin\migrate\source\d6;
4
5 /**
6  * The view mode source.
7  *
8  * @MigrateSource(
9  *   id = "d6_view_mode",
10  *   source_module = "content"
11  * )
12  */
13 class ViewMode extends ViewModeBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function initializeIterator() {
19     $rows = [];
20     $result = $this->prepareQuery()->execute();
21     while ($field_row = $result->fetchAssoc()) {
22       $field_row['display_settings'] = unserialize($field_row['display_settings']);
23       foreach ($this->getViewModes() as $view_mode) {
24         // Append to the return value if the row has display settings for this
25         // view mode and the view mode is neither hidden nor excluded.
26         // @see \Drupal\field\Plugin\migrate\source\d6\FieldInstancePerViewMode::initializeIterator()
27         if (isset($field_row['display_settings'][$view_mode]) && $field_row['display_settings'][$view_mode]['format'] != 'hidden' && empty($field_row['display_settings'][$view_mode]['exclude'])) {
28           if (!isset($rows[$view_mode])) {
29             $rows[$view_mode]['entity_type'] = 'node';
30             $rows[$view_mode]['view_mode'] = $view_mode;
31           }
32         }
33       }
34     }
35
36     return new \ArrayIterator($rows);
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function query() {
43     $query = $this->select('content_node_field_instance', 'cnfi')
44       ->fields('cnfi', [
45         'display_settings',
46       ]);
47
48     return $query;
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function fields() {
55     return [
56       'display_settings' => $this->t('Serialize data with display settings.'),
57     ];
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function getIds() {
64     $ids['view_mode']['type'] = 'string';
65     return $ids;
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function calculateDependencies() {
72     $this->dependencies = parent::calculateDependencies();
73     if (isset($this->configuration['constants']['targetEntityType'])) {
74       $this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['targetEntityType'])->getProvider());
75     }
76     return $this->dependencies;
77   }
78
79 }