UrlAlias.php 2.38 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\migrate\Plugin\migrate\destination\UrlAlias.
 */

namespace Drupal\migrate\Plugin\migrate\destination;

10
use Drupal\Core\Path\AliasStorage;
11 12 13 14 15 16 17 18 19 20 21 22 23
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;

/**
 * @MigrateDestination(
 *   id = "url_alias"
 * )
 */
class UrlAlias extends DestinationBase implements ContainerFactoryPluginInterface {

  /**
24
   * The alias storage service.
25
   *
26
   * @var \Drupal\Core\Path\AliasStorage $aliasStorage
27
   */
28
  protected $aliasStorage;
29 30 31 32 33 34 35 36 37 38 39 40

  /**
   * Constructs an entity destination plugin.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param MigrationInterface $migration
   *   The migration.
41
   * @param \Drupal\Core\Path\AliasStorage $alias_storage
42 43
   *   The path crud service.
   */
44
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, AliasStorage $alias_storage) {
45
    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
46
    $this->aliasStorage = $alias_storage;
47 48 49 50 51 52 53 54 55 56 57
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration = NULL) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $migration,
58
      $container->get('path.alias_storage')
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    );
  }

  /**
   * {@inheritdoc}
   */
  public function import(Row $row, array $old_destination_id_values = array()) {

    $path = $this->path->save(
      $row->getDestinationProperty('source'),
      $row->getDestinationProperty('alias'),
      $row->getDestinationProperty('langcode'),
      $old_destination_id_values ? $old_destination_id_values[0] : NULL
    );

    return array($path['pid']);
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids['pid']['type'] = 'integer';
    return $ids;
  }

  /**
   * {@inheritdoc}
   */
  public function fields(MigrationInterface $migration = NULL) {
    // TODO: Implement fields() method.
  }

}