3 namespace Drupal\taxonomy\Plugin\migrate\source\d7;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
9 * Provides Drupal 7 taxonomy term entity translation source plugin.
12 * id = "d7_taxonomy_term_entity_translation",
13 * source_module = "entity_translation"
16 class TermEntityTranslation extends FieldableEntity {
21 public function query() {
22 $query = $this->select('entity_translation', 'et')
32 ->condition('et.entity_type', 'taxonomy_term')
33 ->condition('et.source', '', '<>');
35 $query->innerJoin('taxonomy_term_data', 'td', 'td.tid = et.entity_id');
36 $query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
38 if (isset($this->configuration['bundle'])) {
39 $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN');
48 public function prepareRow(Row $row) {
49 $tid = $row->getSourceProperty('entity_id');
50 $vocabulary = $row->getSourceProperty('machine_name');
51 $language = $row->getSourceProperty('language');
53 // Get Field API field values.
54 foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) {
55 // Ensure we're using the right language if the entity is translatable.
56 $field_language = $field['translatable'] ? $language : NULL;
57 $row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, NULL, $field_language));
60 // If the term name or term description were replaced by real fields using
61 // the Drupal 7 Title module, use the fields value instead of the term name
62 // or term description.
63 if ($this->moduleExists('title')) {
64 $name_field = $row->getSourceProperty('name_field');
65 if (isset($name_field[0]['value'])) {
66 $row->setSourceProperty('name', $name_field[0]['value']);
68 $description_field = $row->getSourceProperty('description_field');
69 if (isset($description_field[0]['value'])) {
70 $row->setSourceProperty('description', $description_field[0]['value']);
72 if (isset($description_field[0]['format'])) {
73 $row->setSourceProperty('format', $description_field[0]['format']);
77 // Determine if this is a forum container.
78 $forum_container_tids = $this->variableGet('forum_containers', []);
79 $row->setSourceProperty('is_container', in_array($tid, $forum_container_tids));
81 return parent::prepareRow($row);
87 public function fields() {
89 'entity_type' => $this->t('The entity type this translation relates to'),
90 'entity_id' => $this->t('The entity ID this translation relates to'),
91 'revision_id' => $this->t('The entity revision ID this translation relates to'),
92 'language' => $this->t('The target language for this translation.'),
93 'source' => $this->t('The source language from which this translation was created.'),
94 'uid' => $this->t('The author of this translation.'),
95 'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
96 'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'),
97 'created' => $this->t('The Unix timestamp when the translation was created.'),
98 'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'),
99 'name' => $this->t('The name of the term.'),
100 'description' => $this->t('The term description.'),
101 'format' => $this->t('Format of the term description.'),
102 'machine_name' => $this->t('Vocabulary machine name'),
109 public function getIds() {