diff --git a/core/modules/menu_link_content/migration_templates/d7_menu_links.yml b/core/modules/menu_link_content/migration_templates/d7_menu_links.yml index 8581e2c07f6..7f049f7acf7 100644 --- a/core/modules/menu_link_content/migration_templates/d7_menu_links.yml +++ b/core/modules/menu_link_content/migration_templates/d7_menu_links.yml @@ -20,7 +20,7 @@ process: plugin: skip_on_empty method: row 'link/uri': - plugin: d7_internal_uri + plugin: link_uri source: - link_path 'link/options': options 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 index 93656c84787..839b6396063 100644 --- a/core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php +++ b/core/modules/menu_link_content/src/Plugin/migrate/process/LinkUri.php @@ -63,6 +63,9 @@ class LinkUri extends ProcessPluginBase implements ContainerFactoryPluginInterfa $path = ltrim($path, '/'); if (parse_url($path, PHP_URL_SCHEME) === NULL) { + if ($path == '') { + $path = ''; + } $path = 'internal:/' . $path; // Convert entity URIs to the entity scheme, if the path matches a route diff --git a/core/modules/menu_link_content/src/Plugin/migrate/process/d7/InternalUri.php b/core/modules/menu_link_content/src/Plugin/migrate/process/d7/InternalUri.php index 9d373568fcc..fc636758b13 100644 --- a/core/modules/menu_link_content/src/Plugin/migrate/process/d7/InternalUri.php +++ b/core/modules/menu_link_content/src/Plugin/migrate/process/d7/InternalUri.php @@ -2,42 +2,12 @@ namespace Drupal\menu_link_content\Plugin\migrate\process\d7; -use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\ProcessPluginBase; -use Drupal\migrate\Row; +use Drupal\menu_link_content\Plugin\migrate\process\LinkUri; /** - * Process a path into an 'internal:' URI. + * Processes an internal uri into an 'internal:' or 'entity:' URI. * - * @MigrateProcessPlugin( - * id = "d7_internal_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 InternalUri extends ProcessPluginBase { - - /** - * {@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) { - // If $path is the node page (i.e. node/[nid]) then return entity path. - if (preg_match('/^node\/\d+$/', $path)) { - // "entity: URI"s enable the menu link to appear in the Menu Settings - // section on the node edit page. Other entities (e.g. taxonomy terms, - // users) do not have the Menu Settings section. - return 'entity:' . $path; - } - elseif ($path == '') { - return 'internal:/'; - } - else { - return 'internal:/' . $path; - } - } - return $path; - } - -} +class InternalUri extends LinkUri {} diff --git a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d7/MigrateMenuLinkTest.php b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d7/MigrateMenuLinkTest.php index 0c915d42349..1d757a51346 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d7/MigrateMenuLinkTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d7/MigrateMenuLinkTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\menu_link_content\Kernel\Migrate\d7; use Drupal\Core\Menu\MenuTreeParameters; use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\menu_link_content\MenuLinkContentInterface; +use Drupal\node\Entity\Node; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** @@ -18,7 +19,7 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase { /** * {@inheritdoc} */ - public static $modules = array('link', 'menu_ui', 'menu_link_content'); + public static $modules = array('link', 'menu_ui', 'menu_link_content', 'node'); /** * {@inheritdoc} @@ -26,6 +27,13 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase { protected function setUp() { parent::setUp(); $this->installEntitySchema('menu_link_content'); + $this->installEntitySchema('node'); + $node = Node::create([ + 'nid' => 3, + 'title' => 'node link test', + 'type' => 'article', + ]); + $node->save(); $this->executeMigrations(['d7_menu', 'd7_menu_links']); \Drupal::service('router.builder')->rebuild(); } diff --git a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/LinkUriTest.php b/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/LinkUriTest.php index 073180f6b89..d64761257c4 100644 --- a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/LinkUriTest.php +++ b/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/LinkUriTest.php @@ -117,6 +117,10 @@ class LinkUriTest extends UnitTestCase { $expected = 'internal:/test'; $tests['without_scheme'] = [$value, $expected]; + $value = ['']; + $expected = 'internal:/'; + $tests['front'] = [$value, $expected]; + $url = Url::fromRoute('route_name'); $tests['with_route'] = [$value, $expected, $url]; diff --git a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d7/InternalUriTest.php b/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d7/InternalUriTest.php deleted file mode 100644 index 9292718ae48..00000000000 --- a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d7/InternalUriTest.php +++ /dev/null @@ -1,73 +0,0 @@ -processPlugin = new InternalUri([], 'd7_internal_uri', []); - } - - /** - * Tests InternalUri::transform(). - * - * @param array $value - * The value to pass to InternalUri::transform(). - * @param string $expected - * The expected return value of InternalUri::transform(). - * - * @dataProvider providerTestTransform - * - * @covers ::transform - */ - public function testTransform(array $value, $expected) { - $migrate_executable = $this->prophesize(MigrateExecutableInterface::class); - $row = $this->prophesize(Row::class); - - $actual = $this->processPlugin->transform($value, $migrate_executable->reveal(), $row->reveal(), 'link/uri'); - $this->assertEquals($expected, $actual); - } - - /** - * Provides test cases for InternalUriTest::testTransform(). - * - * @return array - * An array of test cases, each which the following values: - * - The value array to pass to InternalUri::transform(). - * - The expected path returned by InternalUri::transform(). - */ - public function providerTestTransform() { - $tests = []; - $tests['with_scheme'] = [['http://example.com'], 'http://example.com']; - $tests['leading_slash'] = [['/test'], 'internal:/test']; - $tests['without_scheme'] = [['test'], 'internal:/test']; - $tests['front'] = [[''], 'internal:/']; - $tests['node'] = [['node/27'], 'entity:node/27']; - return $tests; - } - -}