3 namespace Drupal\migrate\Plugin\migrate\process;
5 use Symfony\Component\DependencyInjection\ContainerInterface;
6 use Drupal\Core\Path\PathValidatorInterface;
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8 use Drupal\migrate\MigrateExecutableInterface;
9 use Drupal\migrate\Plugin\MigrationInterface;
10 use Drupal\migrate\ProcessPluginBase;
11 use Drupal\migrate\Row;
14 * Sets the destination route information based on the source link_path.
16 * The source value is an array of two values:
17 * - link_path: The path or URL of the route.
18 * - options: An array of URL options, e.g. query string, attributes, etc.
27 * - 'https://www.drupal.org'
33 * This will set new_route_field to be a route with the URL
34 * "https://www.drupal.org" and title attribute "Drupal".
40 * another_route_field:
46 * destination: 'node/1'
49 * This will set another_route_field to be a route to the user login page
50 * (user/login) with a query string of "destination=node/1".
52 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
54 * @MigrateProcessPlugin(
58 class Route extends ProcessPluginBase implements ContainerFactoryPluginInterface {
61 * The path validator service.
63 * @var \Drupal\Core\Path\PathValidatorInterface
65 protected $pathValidator;
70 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, PathValidatorInterface $path_validator) {
71 parent::__construct($configuration, $plugin_id, $plugin_definition);
72 $this->migration = $migration;
73 $this->pathValidator = $path_validator;
79 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
85 $container->get('path.validator')
92 * Set the destination route information based on the source link_path.
94 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
95 if (is_string($value)) {
100 list($link_path, $options) = $value;
103 $extracted = $this->pathValidator->getUrlIfValidWithoutAccessCheck($link_path);
107 if ($extracted->isExternal()) {
108 $route['route_name'] = NULL;
109 $route['route_parameters'] = [];
110 $route['options'] = $options;
111 $route['url'] = $extracted->getUri();
114 $route['route_name'] = $extracted->getRouteName();
115 $route['route_parameters'] = $extracted->getRouteParameters();
116 $route['options'] = $extracted->getOptions();
118 if (isset($options['query'])) {
119 // If the querystring is stored as a string (as in D6), convert it
121 if (is_string($options['query'])) {
122 parse_str($options['query'], $old_query);
125 $old_query = $options['query'];
127 $options['query'] = $route['options']['query'] + $old_query;
128 unset($route['options']['query']);
130 $route['options'] = $route['options'] + $options;
131 $route['url'] = NULL;