function TermLocalizedTranslation::prepareRow
Same name in this branch
- 8.9.x core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()
Same name in other branches
- 9 core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()
- 9 core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d7\TermLocalizedTranslation::prepareRow()
- 10 core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()
- 10 core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d7\TermLocalizedTranslation::prepareRow()
- 11.x core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()
- 11.x core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d7\TermLocalizedTranslation::prepareRow()
Overrides Term::prepareRow
File
-
core/
modules/ taxonomy/ src/ Plugin/ migrate/ source/ d7/ TermLocalizedTranslation.php, line 52
Class
- TermLocalizedTranslation
- Gets i18n taxonomy terms from source database.
Namespace
Drupal\taxonomy\Plugin\migrate\source\d7Code
public function prepareRow(Row $row) {
$language = $row->getSourceProperty('ltlanguage');
$tid = $row->getSourceProperty('tid');
// If this row has been migrated it is a duplicate then skip it.
if ($this->idMap
->lookupDestinationIds([
'tid' => $tid,
'language' => $language,
])) {
return FALSE;
}
// Save the translation for the property already in the row.
$property_in_row = $row->getSourceProperty('property');
$row->setSourceProperty($property_in_row . '_translated', $row->getSourceProperty('translation'));
// Get the translation for the property not already in the row and save it
// in the row.
$property_not_in_row = $property_in_row == 'name' ? 'description' : 'name';
// Get the translation, if one exists, for the property not already in the
// row.
$query = $this->select('i18n_string', 'i18n')
->fields('i18n', [
'lid',
])
->condition('i18n.property', $property_not_in_row);
$query->leftJoin('locales_target', 'lt', 'i18n.lid = lt.lid');
$query->condition('lt.language', $language);
$query->addField('lt', 'translation');
$results = $query->execute()
->fetchAssoc();
if (!$results) {
$row->setSourceProperty($property_not_in_row . '_translated', NULL);
}
else {
$row->setSourceProperty($property_not_in_row . '_translated', $results['translation']);
}
parent::prepareRow($row);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.