Same name and namespace in other branches
- 8.9.x core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri
- 9 core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri
Hierarchy
- class \Drupal\menu_link_content\Plugin\migrate\process\LinkUri extends \Drupal\migrate\ProcessPluginBase implements ContainerFactoryPluginInterface
Expanded class hierarchy of LinkUri
1 file declares its use of LinkUri
- LinkUriTest.php in core/
modules/ menu_link_content/ tests/ src/ Kernel/ Plugin/ migrate/ process/ LinkUriTest.php
File
- core/
modules/ menu_link_content/ src/ Plugin/ migrate/ process/ LinkUri.php, line 44
Namespace
Drupal\menu_link_content\Plugin\migrate\processView source
class LinkUri extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager, used to fetch entity link templates.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a LinkUri object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager, used to fetch entity link templates.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
$configuration += [
'validate_route' => TRUE,
];
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
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 ($path == '<nolink>') {
return 'route:<nolink>';
}
$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()) {
$route_name = $url
->getRouteName();
foreach (array_keys($this->entityTypeManager
->getDefinitions()) as $entity_type_id) {
if ($route_name == "entity.{$entity_type_id}.canonical" && isset($url
->getRouteParameters()[$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']) {
return $url
->getUri();
}
else {
throw new MigrateException(sprintf('The path "%s" failed validation.', $path));
}
}
}
return $path;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LinkUri:: |
protected | property | The entity type manager, used to fetch entity link templates. | |
LinkUri:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
LinkUri:: |
public | function | ||
LinkUri:: |
public | function | Constructs a LinkUri object. |