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):

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.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | content_sync-menu_link_url_wrong_after_import-3121639-5.txt | 1.73 KB | geoffreyr |
| #3 | content_sync-menu_link_url_wrong_after_import-3121639-3.patch | 1.36 KB | blanca.esqueda |
| screen.jpeg | 129.79 KB | i-grou |
Comments
Comment #2
blanca.esqueda commentedHi @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
Comment #3
blanca.esqueda commentedOk, 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.
Comment #4
geoffreyr commentedI'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 toentity:node/123. I'm going to see if there's a way to tweak your patch to handle this case.Comment #5
geoffreyr commentedUploaded 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.
Comment #6
tascI 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.
Comment #9
blanca.esqueda commentedThank you @geoffreyr for the update to the patch and @tasc for reviewing.
The patch has been committed.
Comment #10
blanca.esqueda commentedComment #11
blanca.esqueda commentedComment #12
blanca.esqueda commentedChanges to test for menulinks:
https://www.drupal.org/project/content_sync/issues/3049963#comment-14229823