d9aef9162a69760b9567901d26f4c1f2f638b5b7
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / source / d7 / Field.php
1 <?php
2
3 namespace Drupal\field\Plugin\migrate\source\d7;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Drupal 7 field source from database.
10  *
11  * @MigrateSource(
12  *   id = "d7_field"
13  * )
14  */
15 class Field extends DrupalSqlBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function query() {
21     $query = $this->select('field_config', 'fc')
22       ->distinct()
23       ->fields('fc')
24       ->fields('fci', ['entity_type'])
25       ->condition('fc.active', 1)
26       ->condition('fc.deleted', 0)
27       ->condition('fc.storage_active', 1);
28     $query->join('field_config_instance', 'fci', 'fc.id = fci.field_id');
29
30     return $query;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function fields() {
37     return [
38       'field_name' => $this->t('The name of this field.'),
39       'type' => $this->t('The type of this field.'),
40       'module' => $this->t('The module that implements the field type.'),
41       'storage' => $this->t('The field storage.'),
42       'locked' => $this->t('Locked'),
43       'cardinality' => $this->t('Cardinality'),
44       'translatable' => $this->t('Translatable'),
45     ];
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function prepareRow(Row $row, $keep = TRUE) {
52     foreach (unserialize($row->getSourceProperty('data')) as $key => $value) {
53       $row->setSourceProperty($key, $value);
54     }
55     return parent::prepareRow($row);
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function getIds() {
62     return [
63       'field_name' => [
64         'type' => 'string',
65         'alias' => 'fc',
66       ],
67       'entity_type' => [
68         'type' => 'string',
69         'alias' => 'fci',
70       ],
71     ];
72   }
73
74 }