7d4f8dfa2e3dae59f84cc619044406466a7b05a4
[yaffs-website] / web / core / modules / user / src / Plugin / migrate / source / d7 / UserEntityTranslation.php
1 <?php
2
3 namespace Drupal\user\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 user entity translations source plugin.
10  *
11  * @MigrateSource(
12  *   id = "d7_user_entity_translation",
13  *   source_module = "entity_translation"
14  * )
15  */
16 class UserEntityTranslation extends FieldableEntity {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     $query = $this->select('entity_translation', 'et')
23       ->fields('et')
24       ->condition('et.entity_type', 'user')
25       ->condition('et.source', '', '<>');
26
27     return $query;
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function prepareRow(Row $row) {
34     $uid = $row->getSourceProperty('entity_id');
35     $language = $row->getSourceProperty('language');
36
37     // Get Field API field values.
38     foreach ($this->getFields('user') as $field_name => $field) {
39       // Ensure we're using the right language if the entity is translatable.
40       $field_language = $field['translatable'] ? $language : NULL;
41       $row->setSourceProperty($field_name, $this->getFieldValues('user', $field_name, $uid, NULL, $field_language));
42     }
43
44     return parent::prepareRow($row);
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function fields() {
51     return [
52       'entity_type' => $this->t('The entity type this translation relates to'),
53       'entity_id' => $this->t('The entity id this translation relates to'),
54       'revision_id' => $this->t('The entity revision id this translation relates to'),
55       'language' => $this->t('The target language for this translation.'),
56       'source' => $this->t('The source language from which this translation was created.'),
57       'uid' => $this->t('The author of this translation.'),
58       'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
59       'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'),
60       'created' => $this->t('The Unix timestamp when the translation was created.'),
61       'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'),
62     ];
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function getIds() {
69     return [
70       'entity_id' => [
71         'type' => 'integer',
72       ],
73       'language' => [
74         'type' => 'string',
75       ],
76     ];
77   }
78
79 }