You are here

public function TermLocalizedTranslation::prepareRow in Drupal 10

Same name in this branch
  1. 10 core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()
  2. 10 core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d7\TermLocalizedTranslation::prepareRow()
Same name and namespace in other branches
  1. 8 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/d6/TermLocalizedTranslation.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation::prepareRow()

Adds additional data to the row.

Parameters

\Drupal\migrate\Row $row: The row object.

Return value

bool FALSE if this row needs to be skipped.

Overrides Term::prepareRow

File

core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php, line 55

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);
}