CckLink.php 1.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\migrate_drupal\Plugin\migrate\process\d6\CckLink.
 */

namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
11
use Drupal\migrate\Entity\MigrationInterface;
12
use Drupal\migrate\MigrateExecutable;
13
use Drupal\migrate\ProcessPluginBase;
14 15
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\process\Route;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17 18 19 20 21 22

/**
 * @MigrateProcessPlugin(
 *   id = "d6_cck_link"
 * )
 */
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
class CckLink extends ProcessPluginBase implements ContainerFactoryPluginInterface {

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->migration = $migration;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $migration
    );
  }
44 45 46 47 48 49 50 51 52 53 54

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
    list($url, $title, $attributes) = $value;

    // Drupal 6 link attributes are double serialized.
    $attributes = unserialize(unserialize($attributes));

    // Massage the values into the correct form for the link.
55
    $route['uri'] = $url;
56 57 58 59 60 61
    $route['options']['attributes'] = $attributes;
    $route['title'] = $title;
    return $route;
  }

}