33852d6775b515521121735365b81b6e115ddecd
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / source / d6 / FieldInstancePerViewMode.php
1 <?php
2
3 namespace Drupal\field\Plugin\migrate\source\d6;
4
5 use Drupal\node\Plugin\migrate\source\d6\ViewModeBase;
6
7 /**
8  * The field instance per view mode source class.
9  *
10  * @MigrateSource(
11  *   id = "d6_field_instance_per_view_mode",
12  *   source_provider = "content"
13  * )
14  */
15 class FieldInstancePerViewMode extends ViewModeBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function initializeIterator() {
21     $rows = [];
22     $result = $this->prepareQuery()->execute();
23     while ($field_row = $result->fetchAssoc()) {
24       // These are added to every view mode row.
25       $field_row['display_settings'] = unserialize($field_row['display_settings']);
26       $field_row['widget_settings'] = unserialize($field_row['widget_settings']);
27       $bundle = $field_row['type_name'];
28       $field_name = $field_row['field_name'];
29
30       foreach ($this->getViewModes() as $view_mode) {
31         // Append to the return value if the row has display settings for this
32         // view mode and the view mode is neither hidden nor excluded.
33         // @see \Drupal\node\Plugin\migrate\source\d6\ViewMode::initializeIterator()
34         if (isset($field_row['display_settings'][$view_mode]) && $field_row['display_settings'][$view_mode]['format'] != 'hidden' && empty($field_row['display_settings'][$view_mode]['exclude'])) {
35           $index = $view_mode . "." . $bundle . "." . $field_name;
36           $rows[$index]['entity_type'] = 'node';
37           $rows[$index]['view_mode'] = $view_mode;
38           $rows[$index]['type_name'] = $bundle;
39           $rows[$index]['field_name'] = $field_name;
40           $rows[$index]['type'] = $field_row['type'];
41           $rows[$index]['module'] = $field_row['module'];
42           $rows[$index]['weight'] = $field_row['weight'];
43           $rows[$index]['label'] = $field_row['display_settings']['label']['format'];
44           $rows[$index]['display_settings'] = $field_row['display_settings'][$view_mode];
45           $rows[$index]['widget_settings'] = $field_row['widget_settings'];
46         }
47       }
48     }
49
50     return new \ArrayIterator($rows);
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function query() {
57     $query = $this->select('content_node_field_instance', 'cnfi')
58       ->fields('cnfi', [
59         'field_name',
60         'type_name',
61         'weight',
62         'label',
63         'display_settings',
64         'widget_settings',
65       ])
66       ->fields('cnf', [
67         'type',
68         'module',
69       ]);
70     $query->join('content_node_field', 'cnf', 'cnfi.field_name = cnf.field_name');
71     $query->orderBy('cnfi.weight');
72
73     return $query;
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   public function fields() {
80     return [
81       'field_name' => $this->t('The machine name of field.'),
82       'type_name' => $this->t('Content type where this field is used.'),
83       'weight' => $this->t('Weight.'),
84       'label' => $this->t('A name to show.'),
85       'widget_type' => $this->t('Widget type.'),
86       'widget_settings' => $this->t('Serialize data with widget settings.'),
87       'display_settings' => $this->t('Serialize data with display settings.'),
88       'description' => $this->t('A description of field.'),
89       'widget_module' => $this->t('Module that implements widget.'),
90       'widget_active' => $this->t('Status of widget'),
91     ];
92   }
93
94   /**
95    * {@inheritdoc}
96    */
97   public function getIds() {
98     $ids['type_name']['type'] = 'string';
99     $ids['view_mode']['type'] = 'string';
100     $ids['entity_type']['type'] = 'string';
101     $ids['field_name']['type'] = 'string';
102     return $ids;
103   }
104
105 }