function LinkUri::transform

Same name in this branch
  1. main core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri::transform()
Same name and namespace in other branches
  1. 11.x core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri::transform()
  2. 10 core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri::transform()
  3. 9 core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri::transform()
  4. 8.9.x core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri::transform()
  5. 11.x core/modules/migrate/src/Plugin/migrate/process/LinkUri.php \Drupal\migrate\Plugin\migrate\process\LinkUri::transform()

File

core/modules/migrate/src/Plugin/migrate/process/LinkUri.php, line 60

Class

LinkUri
Generates an internal URI from the source value.

Namespace

Drupal\migrate\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  $path = ltrim($value, '/');
  if (parse_url($path, PHP_URL_SCHEME) === NULL) {
    if ($path === '<front>') {
      $path = '';
    }
    elseif (empty($path) || in_array($path, [
      '<nolink>',
      '<none>',
    ], TRUE)) {
      return 'route:<nolink>';
    }
    elseif ($path === '<button>') {
      return 'route:<button>';
    }
    $path = 'internal:/' . $path;
    // Convert entity URIs to the entity scheme, if the path matches a route
    // of the form "entity.$entity_type_id.canonical".
    // @see \Drupal\Core\Url::fromEntityUri()
    $url = Url::fromUri($path);
    if ($url->isRouted()) {
      if (preg_match('/^entity\\.(.*)\\.canonical$/', $url->getRouteName(), $matches)) {
        $entity_type_id = $matches[1];
        if (isset($url->getRouteParameters()[$entity_type_id], $this->entityTypeManager
          ->getDefinitions()[$entity_type_id])) {
          return "entity:{$entity_type_id}/" . $url->getRouteParameters()[$entity_type_id];
        }
      }
    }
    else {
      // If the URL is not routed, we might want to get something back to do
      // other processing. If this is the case, the "validate_route"
      // configuration option can be set to FALSE to return the URI.
      if ($this->configuration['validate_route']) {
        throw new MigrateException(sprintf('The path "%s" failed validation.', $path));
      }
      return $url->getUri();
    }
  }
  return $path;
}

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