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

jseffel created an issue. See original summary.

gceja’s picture

We 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

darrenwh’s picture

Hi,

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 :

if ($node->isNew() && empty($node->in_preview)) {
mbrc’s picture

While 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.

krina.addweb’s picture

Status: Needs review » Reviewed & tested by the community

Hi mbrc, Thanks! for the patch this really solved my issue.

Berdir’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Entity 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.