3 namespace Drupal\node\Plugin\migrate\source\d7;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
9 * Provides Drupal 7 node entity translations source plugin.
12 * id = "d7_node_entity_translation",
13 * source_module = "entity_translation"
16 class NodeEntityTranslation extends FieldableEntity {
21 public function query() {
22 $query = $this->select('entity_translation', 'et')
34 ->condition('et.entity_type', 'node')
35 ->condition('et.source', '', '<>');
37 $query->addField('nr', 'uid', 'revision_uid');
39 $query->innerJoin('node', 'n', 'n.nid = et.entity_id');
40 $query->innerJoin('node_revision', 'nr', 'nr.vid = et.revision_id');
42 if (isset($this->configuration['node_type'])) {
43 $query->condition('n.type', $this->configuration['node_type']);
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');
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));
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']);
74 return parent::prepareRow($row);
80 public function fields() {
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)'),
105 public function getIds() {