function TermLocalizedTranslation::prepareRow

Same name in this branch
  1. 11.x core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d7\TermLocalizedTranslation::prepareRow()
Same name in other branches
  1. 9 core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()
  2. 9 core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d7\TermLocalizedTranslation::prepareRow()
  3. 8.9.x core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()
  4. 8.9.x core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d7\TermLocalizedTranslation::prepareRow()
  5. 10 core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()
  6. 10 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/d6/TermLocalizedTranslation.php, line 57

Class

TermLocalizedTranslation
Drupal 6 i18n taxonomy terms source from database.

Namespace

Drupal\taxonomy\Plugin\migrate\source\d6

Code

public function prepareRow(Row $row) {
    $language = $row->getSourceProperty('ltlanguage');
    $row->setSourceProperty('language', $language);
    $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 this property.
    $property = $row->getSourceProperty('property');
    $row->setSourceProperty($property . '_translated', $row->getSourceProperty('translation'));
    // Get the translation, if one exists, for the property not already in the
    // row.
    $other_property = $property == 'name' ? 'description' : 'name';
    $query = $this->select('i18n_strings', 'i18n')
        ->fields('i18n', [
        'lid',
    ])
        ->condition('i18n.type', 'term')
        ->condition('i18n.property', $other_property)
        ->condition('i18n.objectid', $tid);
    $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($other_property . '_translated', $results['translation']);
    }
    else {
        // The translation does not exist.
        $row->setSourceProperty($other_property . '_translated', NULL);
    }
    return parent::prepareRow($row);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.