diff --git a/core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php b/core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php new file mode 100644 index 0000000000000000000000000000000000000000..93656c84787123546adcf4dc2aff773eda864b00 --- /dev/null +++ b/core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php @@ -0,0 +1,84 @@ +<?php + +namespace Drupal\menu_link_content\Plugin\migrate\process; + +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Url; +use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\ProcessPluginBase; +use Drupal\migrate\Row; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Processes a link path into an 'internal:' or 'entity:' URI. + * + * @MigrateProcessPlugin( + * id = "link_uri" + * ) + */ +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) { + 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) { + list($path) = $value; + $path = ltrim($path, '/'); + + if (parse_url($path, PHP_URL_SCHEME) === NULL) { + $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]; + } + } + } + } + return $path; + } + +} diff --git a/core/modules/menu_link_content/src/Plugin/migrate/process/d6/LinkUri.php b/core/modules/menu_link_content/src/Plugin/migrate/process/d6/LinkUri.php index 08c45d812737898989d776b30f1d7e440401cb6c..46b53a04e69cec581792a086e055ef8c5631e98d 100644 --- a/core/modules/menu_link_content/src/Plugin/migrate/process/d6/LinkUri.php +++ b/core/modules/menu_link_content/src/Plugin/migrate/process/d6/LinkUri.php @@ -2,83 +2,12 @@ namespace Drupal\menu_link_content\Plugin\migrate\process\d6; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Url; -use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\ProcessPluginBase; -use Drupal\migrate\Row; -use Symfony\Component\DependencyInjection\ContainerInterface; +use \Drupal\menu_link_content\Plugin\migrate\process\LinkUri as RealLinkUri; /** * Processes a link path into an 'internal:' or 'entity:' URI. * - * @MigrateProcessPlugin( - * id = "link_uri" - * ) + * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use + * \Drupal\menu_link_content\Plugin\migrate\process\LinkUri instead. */ -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) { - 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) { - list($path) = $value; - $path = ltrim($path, '/'); - - if (parse_url($path, PHP_URL_SCHEME) === NULL) { - $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]; - } - } - } - } - return $path; - } - -} +class LinkUri extends RealLinkUri {} diff --git a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d6/LinkUriTest.php b/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/LinkUriTest.php similarity index 94% rename from core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d6/LinkUriTest.php rename to core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/LinkUriTest.php index 93a72802a0cf2fa636a74a8c7222bbbd23b6a842..073180f6b897c219d69392d818b0f2df145d9640 100644 --- a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d6/LinkUriTest.php +++ b/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/LinkUriTest.php @@ -1,10 +1,10 @@ <?php -namespace Drupal\Tests\menu_link_content\Unit\Plugin\migrate\process\d6; +namespace Drupal\Tests\menu_link_content\Unit\Plugin\migrate\process; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Url; -use Drupal\menu_link_content\Plugin\migrate\process\d6\LinkUri; +use Drupal\menu_link_content\Plugin\migrate\process\LinkUri; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; use Drupal\Tests\UnitTestCase; @@ -12,11 +12,11 @@ use Drupal\Core\Path\PathValidator; /** - * Tests \Drupal\menu_link_content\Plugin\migrate\process\d6\LinkUri. + * Tests \Drupal\menu_link_content\Plugin\migrate\process\LinkUri. * * @group menu_link_content * - * @coversDefaultClass \Drupal\menu_link_content\Plugin\migrate\process\d6\LinkUri + * @coversDefaultClass \Drupal\menu_link_content\Plugin\migrate\process\LinkUri */ class LinkUriTest extends UnitTestCase { @@ -30,7 +30,7 @@ class LinkUriTest extends UnitTestCase { /** * The 'link_uri' process plugin being tested. * - * @var \Drupal\menu_link_content\Plugin\migrate\process\d6\LinkUri + * @var \Drupal\menu_link_content\Plugin\migrate\process\LinkUri */ protected $processPlugin;