You are here

public function UrlAlias::import in Drupal 8

Throws

\Drupal\migrate\MigrateException When an entity cannot be looked up.

\Drupal\migrate\Exception\EntityValidationException When an entity validation hasn't been passed.

Overrides EntityContentBase::import

File

core/modules/path/src/Plugin/migrate/destination/UrlAlias.php, line 27

Class

UrlAlias
Legacy destination class for non-entity path aliases.

Namespace

Drupal\path\Plugin\migrate\destination

Code

public function import(Row $row, array $old_destination_id_values = []) {
  if ($row
    ->getDestinationProperty('source')) {
    $row
      ->setDestinationProperty('path', $row
      ->getDestinationProperty('source'));
  }
  $path = $row
    ->getDestinationProperty('path');

  // Check if this alias is for a node and if that node is a translation.
  if (preg_match('/^\\/node\\/\\d+$/', $path) && $row
    ->hasDestinationProperty('node_translation')) {

    // Replace the alias source with the translation source path.
    $node_translation = $row
      ->getDestinationProperty('node_translation');
    $row
      ->setDestinationProperty('path', '/node/' . $node_translation[0]);
    $row
      ->setDestinationProperty('langcode', $node_translation[1]);
  }
  return parent::import($row, $old_destination_id_values);
}