Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When a user previews a node a menu link is generated. The link is never used and is left dangling in the system.
Steps to reproduce:
1. node/add/article
2. Enter title and provide a menu link
3. Press preview
4. Navigate to /admin/structure/menu/manage/main: You will se the menu link pointing to node/UUID
Performed on clean vanilla Drupal 8.2.1 with Token 1.0-beta2.
token_node_menu_link_submit() is the culprit here and should probobly check if the user has pressed the preview button or save button.
Comments
Comment #2
gceja CreditAttribution: gceja commentedWe experienced the same issue.
When going to add a new page, then clicking on the “Provide a menu link”.
Then pressing “Preview”, a temporary menu link gets generated.
And when leaving the new page, because you decide you don’t need it, that temporary menu link remains and shows up on the menu.
This is an issue because now we have broken links showing up on the menu.
Tested on:
Drupal 8.2.3
Token 1.0.0-beta2
Comment #3
darrenwh CreditAttribution: darrenwh as a volunteer and at Investis Digital commentedHi,
The bug is on line 778 of token.module, the system is not looking for the flag $node->in_preview. Unfortunately following further investigation the flag is not set on the node, this will need further investigation.
So the fix will be to add a check like :
Comment #4
mbrc CreditAttribution: mbrc at Unic commentedWhile the in_preview flag is not yet available, we can check the triggering element in $form_state. I'm not certain that checking the generated ID of the element is the best way to go, and I'm sure that this change needs some tests, but here's a patch that fixes the issue until there's a better solution.
Comment #5
krina.addweb CreditAttribution: krina.addweb at AddWeb Solution Pvt. Ltd. commentedHi mbrc, Thanks! for the patch this really solved my issue.
Comment #6
BerdirEntity builders are called before submit buttons, and in_preview is set there.
Wondering if we should instead add this as a submit callback, especially after #2068063: Change "Save and keep un-/published" buttons to a "Published" checkbox and an included "Save" button is in. Because every ajax callback also calls this I think.
Tests would be great as well.
Comment #7
sukotto CreditAttribution: sukotto commented#4 worked for us. Thank you!
If anyone reads this and doesn't know how to use the patch, let me share a sanitized version of our deployment instructions:
cd /var/www/html/examplecom/modules/token
cp token.module /tmp/token.module.pre-patch
patch -p1 < /tmp/token_node_preview_menu_link-2823731-4.patch
Sample output:
diff /tmp/token.module.pre-patch token.module
Sample output:
https://example.com/admin/config/development/performance
Comment #8
lil.destro CreditAttribution: lil.destro as a volunteer and commentedPatch was failing to apply with composer rerolled with latest dev.
Comment #9
shubham.prakash CreditAttribution: shubham.prakash at OpenSense Labs commentedComment #10
szecsodimlaszlo CreditAttribution: szecsodimlaszlo commentedI had the same problem.
I can confirm that the patch #8 solved it.
Comment #11
malte.koelle CreditAttribution: malte.koelle at Unic commentedPatch #8 works for me. I extended the patch with a test to cover this scenario.
Comment #12
rosieneko CreditAttribution: rosieneko commentedI can confirm that patch #11 works for me and solves the issue for me. There is no menu link created in Preview mode when the node hasn't been saved yet.
Comment #14
BerdirThanks for the test. Made some coding standard and deprecation fixes: