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 / FieldInstance.php
1 <?php
2
3 namespace Drupal\field\Plugin\migrate\source\d6;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Drupal 6 field instances source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_field_instance",
13  *   source_module = "content"
14  * )
15  */
16 class FieldInstance extends DrupalSqlBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     $query = $this->select('content_node_field_instance', 'cnfi')->fields('cnfi');
23     if (isset($this->configuration['node_type'])) {
24       $query->condition('cnfi.type_name', $this->configuration['node_type']);
25     }
26     $query->join('content_node_field', 'cnf', 'cnf.field_name = cnfi.field_name');
27     $query->fields('cnf');
28
29     return $query;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public function fields() {
36     return [
37       'field_name' => $this->t('The machine name of field.'),
38       'type_name' => $this->t('Content type where this field is in use.'),
39       'weight' => $this->t('Weight.'),
40       'label' => $this->t('A name to show.'),
41       'widget_type' => $this->t('Widget type.'),
42       'widget_settings' => $this->t('Serialize data with widget settings.'),
43       'display_settings' => $this->t('Serialize data with display settings.'),
44       'description' => $this->t('A description of field.'),
45       'widget_module' => $this->t('Module that implements widget.'),
46       'widget_active' => $this->t('Status of widget'),
47       'module' => $this->t('The module that provides the field.'),
48     ];
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function prepareRow(Row $row) {
55     // Unserialize data.
56     $widget_settings = unserialize($row->getSourceProperty('widget_settings'));
57     $display_settings = unserialize($row->getSourceProperty('display_settings'));
58     $global_settings = unserialize($row->getSourceProperty('global_settings'));
59     $row->setSourceProperty('widget_settings', $widget_settings);
60     $row->setSourceProperty('display_settings', $display_settings);
61     $row->setSourceProperty('global_settings', $global_settings);
62     return parent::prepareRow($row);
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function getIds() {
69     $ids = [
70       'field_name' => [
71         'type' => 'string',
72         'alias' => 'cnfi',
73       ],
74       'type_name' => [
75         'type' => 'string',
76       ],
77     ];
78     return $ids;
79   }
80
81 }