I've created a node and menu link for it (added to Footer menu).
Then I've exported it using content_sync and imported on the other site and noticed couple of weird things:
1. When I open a menu and click edit next to the menu item I can see wrong link: ntity.node.canonical;node=2 instead of Terms and Conditions (2) (or /node/2):
Menu has wrong link

I've looked at the menu_link_content_data db table and can see that link__uri field has route:entity.node.canonical;node=2 value instead of entity:node/2.

So if I click Save in that form I would get an error message: 'Manually entered paths should start with one of the following characters: / ? #'.
And I need to change url manually before saving menu item.

2. At the same time menu link works as expected - if user clicks menu item in the footer he would be redirected to correct page (href is correct).

Despite the fact that link in the menu is working, it would be great to fix that issue so that it would be safer and easier to edit menu items.

Comments

ivanklochko created an issue. See original summary.

blanca.esqueda’s picture

Hi @ivanklochko

Thank you for the report.
I took a look, and this is happening on the function: alterMenuLink, in the file: ContentImporter.php

For some reason, 'toUriString' is returning the route: 'route:entity.node.canonical;node=16'
instead of the uri schema: 'entity:node/16'

I tried to get the URI with the scheme from the entity in different ways: url->toString(); url->getInternalPath(); url->getRouteName(); ... but nothing seems to work.
Something like the D7 entity_uri is needed.

I added a comment to:
https://www.drupal.org/project/drupal/issues/2722303#comment-13610313

blanca.esqueda’s picture

Version: 8.x-2.1 » 8.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new1.36 KB

Ok, after a few hrs trying to figure this out I created a patch base on how the following class converts entity URIs to the entity scheme:
https://api.drupal.org/api/drupal/core%21modules%21menu_link_content%21s...

I think the patch resolves this issue.

geoffreyr’s picture

I've encountered a case where this patch doesn't quite fix the issue, when using a node as part of an argument in a Views path. Although the URI for the menu_content_link item might be something like internal:/path/to/view/123, it's somehow treating the route_name as entity.node.canonical and thereby translating it to entity:node/123. I'm going to see if there's a way to tweak your patch to handle this case.

geoffreyr’s picture

Uploaded my patch. A relatively small change, and I'm not sure it'll handle all the cases that we need to, but it should at least preserve Views paths that use a node ID as an argument.

tasc’s picture

I noticed the bug when reviewing the menu link in the node-edit-form as the link element was empty.
The menu however showed and linked correctly.

With patch #5 menu-links are now created correctly and also show up in the node form.

  • Blanca.Esqueda authored 4e2a7f4 on 8.x-2.x
    Issue #3121639 by Blanca.Esqueda: Menu link url is wrong after import
    

  • geoffreyr authored 743f646 on 8.x-2.x
    Issue #3121639 by Blanca.Esqueda, i-grou, geoffreyr: Menu link url is...
blanca.esqueda’s picture

Thank you @geoffreyr for the update to the patch and @tasc for reviewing.
The patch has been committed.

blanca.esqueda’s picture

Status: Needs review » Reviewed & tested by the community
blanca.esqueda’s picture

Status: Reviewed & tested by the community » Fixed
blanca.esqueda’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.