class LinkUri in Drupal 8
Same name in this branch
- 8 core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri
- 8 core/modules/menu_link_content/src/Plugin/migrate/process/d6/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\d6\LinkUri
Same name and namespace in other branches
- 9 core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri
- 10 core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php \Drupal\menu_link_content\Plugin\migrate\process\LinkUri
Generates an internal URI from the source value.
Converts the source path value to an 'entity:', 'internal:' or 'base:' URI.
Available configuration keys:
- source: A source path to be converted into an URI.
- validate_route: (optional) Whether the plugin should validate that the URI
derived from the source link path has a valid Drupal route.
- TRUE: Throw a MigrateException if the resulting URI is not routed. This value is the default.
- FALSE: Return the URI for the unrouted path.
Examples:
process:
link/uri:
plugin: link_uri
validate_route: false
source: link_path
This will set the uri property of link to the internal notation of link_path without validating if the resulting URI is valid. For example, if the 'link_path' property is 'node/12', the uri property value of link will be 'entity:node/12'.
Plugin annotation
@MigrateProcessPlugin(
id = "link_uri"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\menu_link_content\Plugin\migrate\process\LinkUri implements ContainerFactoryPluginInterface
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LinkUri
3 files declare their use of LinkUri
- InternalUri.php in core/
modules/ menu_link_content/ src/ Plugin/ migrate/ process/ d7/ InternalUri.php - LinkUri.php in core/
modules/ menu_link_content/ src/ Plugin/ migrate/ process/ d6/ LinkUri.php - 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 46
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) {
if (is_array($value)) {
$value = reset($value);
@trigger_error('Passing an array as source value into the link_uri migrate process plugin is deprecated in drupal:8.8.0. The possibility to pass an array as source value to the plugin will be removed in drupal:9.0.0. Pass a string value instead. See https://www.drupal.org/node/3043694', E_USER_DEPRECATED);
}
$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 |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
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 |
Performs the associated process. Overrides ProcessPluginBase:: |
|
LinkUri:: |
public | function |
Constructs a LinkUri object. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ProcessPluginBase:: |
public | function |
Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface:: |
3 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |