Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / source / d6 / FieldInstancePerFormDisplay.php
1 <?php
2
3 namespace Drupal\field\Plugin\migrate\source\d6;
4
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6
7 /**
8  * The field instance per form display source class.
9  *
10  * @MigrateSource(
11  *   id = "d6_field_instance_per_form_display",
12  *   source_module = "content"
13  * )
14  */
15 class FieldInstancePerFormDisplay extends DrupalSqlBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function initializeIterator() {
21     $rows = [];
22     $result = $this->prepareQuery()->execute();
23     while ($field_row = $result->fetchAssoc()) {
24       $bundle = $field_row['type_name'];
25       $field_name = $field_row['field_name'];
26
27       $index = "$bundle.$field_name";
28       $rows[$index]['type_name'] = $bundle;
29       $rows[$index]['widget_active'] = (bool) $field_row['widget_active'];
30       $rows[$index]['field_name'] = $field_name;
31       $rows[$index]['type'] = $field_row['type'];
32       $rows[$index]['module'] = $field_row['module'];
33       $rows[$index]['weight'] = $field_row['weight'];
34       $rows[$index]['widget_type'] = $field_row['widget_type'];
35       $rows[$index]['widget_settings'] = unserialize($field_row['widget_settings']);
36       $rows[$index]['display_settings'] = unserialize($field_row['display_settings']);
37     }
38
39     return new \ArrayIterator($rows);
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function query() {
46     $query = $this->select('content_node_field_instance', 'cnfi')
47       ->fields('cnfi', [
48         'field_name',
49         'type_name',
50         'weight',
51         'label',
52         'widget_type',
53         'widget_settings',
54         'display_settings',
55         'description',
56         'widget_module',
57         'widget_active',
58       ])
59       ->fields('cnf', [
60         'type',
61         'module',
62       ]);
63     $query->join('content_node_field', 'cnf', 'cnfi.field_name = cnf.field_name');
64     $query->orderBy('cnfi.weight');
65
66     return $query;
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function fields() {
73     return [
74       'field_name' => $this->t('The machine name of field.'),
75       'type_name' => $this->t('Content type where this field is used.'),
76       'weight' => $this->t('Weight.'),
77       'label' => $this->t('A name to show.'),
78       'widget_type' => $this->t('Widget type.'),
79       'widget_settings' => $this->t('Serialize data with widget settings.'),
80       'display_settings' => $this->t('Serialize data with display settings.'),
81       'description' => $this->t('A description of field.'),
82       'widget_module' => $this->t('Module that implements widget.'),
83       'widget_active' => $this->t('Status of widget'),
84     ];
85   }
86
87   /**
88    * {@inheritdoc}
89    */
90   public function getIds() {
91     $ids['type_name']['type'] = 'string';
92     $ids['field_name']['type'] = 'string';
93     return $ids;
94   }
95
96 }