ce698161634cd5af8a8adc9407309c298d608c2b
[yaffs-website] / web / core / modules / node / src / Plugin / migrate / source / d7 / NodeEntityTranslation.php
1 <?php
2
3 namespace Drupal\node\Plugin\migrate\source\d7;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
7
8 /**
9  * Provides Drupal 7 node entity translations source plugin.
10  *
11  * @MigrateSource(
12  *   id = "d7_node_entity_translation",
13  *   source_module = "entity_translation"
14  * )
15  */
16 class NodeEntityTranslation extends FieldableEntity {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     $query = $this->select('entity_translation', 'et')
23       ->fields('et')
24       ->fields('n', [
25         'title',
26         'type',
27         'promote',
28         'sticky',
29       ])
30       ->fields('nr', [
31         'log',
32         'timestamp',
33       ])
34       ->condition('et.entity_type', 'node')
35       ->condition('et.source', '', '<>');
36
37     $query->addField('nr', 'uid', 'revision_uid');
38
39     $query->innerJoin('node', 'n', 'n.nid = et.entity_id');
40     $query->innerJoin('node_revision', 'nr', 'nr.vid = et.revision_id');
41
42     if (isset($this->configuration['node_type'])) {
43       $query->condition('n.type', $this->configuration['node_type']);
44     }
45
46     return $query;
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function prepareRow(Row $row) {
53     $nid = $row->getSourceProperty('entity_id');
54     $vid = $row->getSourceProperty('revision_id');
55     $type = $row->getSourceProperty('type');
56     $language = $row->getSourceProperty('language');
57
58     // Get Field API field values.
59     foreach ($this->getFields('node', $type) as $field_name => $field) {
60       // Ensure we're using the right language if the entity is translatable.
61       $field_language = $field['translatable'] ? $language : NULL;
62       $row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, $field_language));
63     }
64
65     // If the node title was replaced by a real field using the Drupal 7 Title
66     // module, use the field value instead of the node title.
67     if ($this->moduleExists('title')) {
68       $title_field = $row->getSourceProperty('title_field');
69       if (isset($title_field[0]['value'])) {
70         $row->setSourceProperty('title', $title_field[0]['value']);
71       }
72     }
73
74     return parent::prepareRow($row);
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function fields() {
81     return [
82       'entity_type' => $this->t('The entity type this translation relates to'),
83       'entity_id' => $this->t('The entity ID this translation relates to'),
84       'revision_id' => $this->t('The entity revision ID this translation relates to'),
85       'language' => $this->t('The target language for this translation.'),
86       'source' => $this->t('The source language from which this translation was created.'),
87       'uid' => $this->t('The author of this translation.'),
88       'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
89       'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'),
90       'created' => $this->t('The Unix timestamp when the translation was created.'),
91       'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'),
92       'title' => $this->t('Node title'),
93       'type' => $this->t('Node type'),
94       'promote' => $this->t('Promoted to front page'),
95       'sticky' => $this->t('Sticky at top of lists'),
96       'log' => $this->t('Revision log'),
97       'timestamp' => $this->t('The timestamp the latest revision of this node was created.'),
98       'revision_uid' => $this->t('Revision authored by (uid)'),
99     ];
100   }
101
102   /**
103    * {@inheritdoc}
104    */
105   public function getIds() {
106     return [
107       'entity_id' => [
108         'type' => 'integer',
109         'alias' => 'et',
110       ],
111       'language' => [
112         'type' => 'string',
113         'alias' => 'et',
114       ],
115     ];
116   }
117
118 }