function Route::transform

Same name in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/migrate/process/Route.php \Drupal\migrate\Plugin\migrate\process\Route::transform()
  2. 10 core/modules/migrate/src/Plugin/migrate/process/Route.php \Drupal\migrate\Plugin\migrate\process\Route::transform()
  3. 11.x core/modules/migrate/src/Plugin/migrate/process/Route.php \Drupal\migrate\Plugin\migrate\process\Route::transform()

Set the destination route information based on the source link_path.

Overrides ProcessPluginBase::transform

File

core/modules/migrate/src/Plugin/migrate/process/Route.php, line 99

Class

Route
Sets the destination route information based on the source link_path.

Namespace

Drupal\migrate\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    if (is_string($value)) {
        $link_path = $value;
        $options = [];
    }
    else {
        [
            $link_path,
            $options,
        ] = $value;
    }
    $extracted = $this->pathValidator
        ->getUrlIfValidWithoutAccessCheck($link_path);
    $route = [];
    if ($extracted) {
        if ($extracted->isExternal()) {
            $route['route_name'] = NULL;
            $route['route_parameters'] = [];
            $route['options'] = $options;
            $route['url'] = $extracted->getUri();
        }
        else {
            $route['route_name'] = $extracted->getRouteName();
            $route['route_parameters'] = $extracted->getRouteParameters();
            $route['options'] = $extracted->getOptions();
            if (isset($options['query'])) {
                // If the querystring is stored as a string (as in D6), convert it
                // into an array.
                if (is_string($options['query'])) {
                    parse_str($options['query'], $old_query);
                }
                else {
                    $old_query = $options['query'];
                }
                $options['query'] = $route['options']['query'] + $old_query;
                unset($route['options']['query']);
            }
            $route['options'] = $route['options'] + $options;
            $route['url'] = NULL;
        }
    }
    return $route;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.