UrlAlias.php 2.32 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\PathInterface;
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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 {

  /**
   * The path crud service.
   *
26
   * @var \Drupal\Core\Path\PathInterface $path
27 28 29 30 31 32 33 34 35 36 37 38 39 40
   */
  protected $path;

  /**
   * 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\PathInterface $path
42 43
   *   The path crud service.
   */
44
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, PathInterface $path) {
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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
    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
    $this->path = $path;
  }

  /**
   * {@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,
      $container->get('path.crud')
    );
  }

  /**
   * {@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.
  }

}