Skip to content

Instantly share code, notes, and snippets.

@manojbisht891
Created July 31, 2021 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manojbisht891/13b3ee2d0d7785dcd28ec45a224e924d to your computer and use it in GitHub Desktop.
Save manojbisht891/13b3ee2d0d7785dcd28ec45a224e924d to your computer and use it in GitHub Desktop.
TermTranslationSet.php
<?php
namespace Drupal\example\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
use Drupal\taxonomy\Entity\Term;
/**
* Provides Drupal 7 taxonomy term locales source plugin.
*
* @MigrateSource(
* id = "d7_taxonomy_term_entity_translation_set",
* source_module = "i18n"
* )
*/
class TermTranslationSet extends FieldableEntity {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('taxonomy_term_data', 'ttd')->fields('ttd');
$query->addExpression(" (SELECT MIN(tid) FROM taxonomy_term_data ttd2 WHERE ttd2.i18n_tsid=ttd.i18n_tsid) ", "ttd2_tid");
$query->innerJoin('taxonomy_vocabulary', 'tv', 'ttd.vid=tv.vid');
if ($this->configuration['bundle']) {
$query->condition('tv.machine_name', $this->configuration['bundle']);
}
$query->condition('ttd.i18n_tsid', 0, '<>');
$query->orderBy('ttd.i18n_tsid', 'DESC');
$query->orderBy('ttd.tid', 'ASC');
return $query;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$vocabulary = $row->getSourceProperty('bundle');
$language = $row->getSourceProperty('language');
$tid = $row->getSourceProperty('tid');
foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) {
$row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, NULL, $language));
}
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'tid' => $this->t('TID of Taxonomy Term.'),
'name' => $this->t('Name of Taxonomy Term.'),
'description' => $this->t('Description of Taxonomy Term.'),
'language' => $this->t('The target language for this translation.'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'tid' => [
'type' => 'integer',
'alias' => 'ttd',
],
'language' => [
'type' => 'string',
'alias' => 'ttd',
],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment