View source
<?php
namespace Drupal\path\Plugin\migrate\destination;
use Drupal\Core\Path\AliasStorage;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
class UrlAlias extends DestinationBase implements ContainerFactoryPluginInterface {
protected $aliasStorage;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, AliasStorage $alias_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->aliasStorage = $alias_storage;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
->get('path.alias_storage'));
}
public function import(Row $row, array $old_destination_id_values = array()) {
$path = $this->aliasStorage
->save($row
->getDestinationProperty('source'), $row
->getDestinationProperty('alias'), $row
->getDestinationProperty('langcode'), $old_destination_id_values ? $old_destination_id_values[0] : NULL);
return array(
$path['pid'],
);
}
public function getIds() {
$ids['pid']['type'] = 'integer';
return $ids;
}
public function fields(MigrationInterface $migration = NULL) {
return [
'pid' => 'The path id',
'source' => 'The source path.',
'alias' => 'The url alias.',
'langcode' => 'The language code for the url.',
];
}
}