X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Ftaxonomy%2Fsrc%2FPlugin%2Fmigrate%2Fsource%2Fd7%2FTermEntityTranslation.php;fp=web%2Fcore%2Fmodules%2Ftaxonomy%2Fsrc%2FPlugin%2Fmigrate%2Fsource%2Fd7%2FTermEntityTranslation.php;h=0ba70c8d2b03eea797a68f4e75f93665637bbb1a;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermEntityTranslation.php b/web/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermEntityTranslation.php new file mode 100644 index 000000000..0ba70c8d2 --- /dev/null +++ b/web/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermEntityTranslation.php @@ -0,0 +1,122 @@ +select('entity_translation', 'et') + ->fields('et') + ->fields('td', [ + 'name', + 'description', + 'format', + ]) + ->fields('tv', [ + 'machine_name', + ]) + ->condition('et.entity_type', 'taxonomy_term') + ->condition('et.source', '', '<>'); + + $query->innerJoin('taxonomy_term_data', 'td', 'td.tid = et.entity_id'); + $query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); + + if (isset($this->configuration['bundle'])) { + $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN'); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $tid = $row->getSourceProperty('entity_id'); + $vocabulary = $row->getSourceProperty('machine_name'); + $language = $row->getSourceProperty('language'); + + // Get Field API field values. + foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) { + // Ensure we're using the right language if the entity is translatable. + $field_language = $field['translatable'] ? $language : NULL; + $row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, NULL, $field_language)); + } + + // If the term name or term description were replaced by real fields using + // the Drupal 7 Title module, use the fields value instead of the term name + // or term description. + if ($this->moduleExists('title')) { + $name_field = $row->getSourceProperty('name_field'); + if (isset($name_field[0]['value'])) { + $row->setSourceProperty('name', $name_field[0]['value']); + } + $description_field = $row->getSourceProperty('description_field'); + if (isset($description_field[0]['value'])) { + $row->setSourceProperty('description', $description_field[0]['value']); + } + if (isset($description_field[0]['format'])) { + $row->setSourceProperty('format', $description_field[0]['format']); + } + } + + // Determine if this is a forum container. + $forum_container_tids = $this->variableGet('forum_containers', []); + $row->setSourceProperty('is_container', in_array($tid, $forum_container_tids)); + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'entity_type' => $this->t('The entity type this translation relates to'), + 'entity_id' => $this->t('The entity ID this translation relates to'), + 'revision_id' => $this->t('The entity revision ID this translation relates to'), + 'language' => $this->t('The target language for this translation.'), + 'source' => $this->t('The source language from which this translation was created.'), + 'uid' => $this->t('The author of this translation.'), + 'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'), + 'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'), + 'created' => $this->t('The Unix timestamp when the translation was created.'), + 'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'format' => $this->t('Format of the term description.'), + 'machine_name' => $this->t('Vocabulary machine name'), + ]; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return [ + 'entity_id' => [ + 'type' => 'integer', + 'alias' => 'et', + ], + 'language' => [ + 'type' => 'string', + 'alias' => 'et', + ], + ]; + } + +}