Introduced with #2670120: Patterns with node:menu-link tokens don't work on first node save, if a menu link has been added as a link to a node and subsequently disabled through the menu UI it will be enabled again when the node is saved again through the UI.
The offending code is in token_node_menu_link_submit() line 731, hard sets the enabled flag to 1.
This is because the function checks:
$values = $form_state->getValue('menu');
if (!empty($values['enabled']) && trim($values['title']))
To determine that the menu link should be worked on. Technically $values['enabled'] should denote whether the menu link is disabled or not but it is actually used to control the display of the menu link editing interface on the node form. I.e it is controlled by the checkbox "Provide a menu link".
A node can provide a menu link but it can be disabled.
The menu_ui gets around overwriting the enabled flag like this because it only sets the enabled flag for new menu links (see _menu_ui_node_save())
Comment | File | Size | Author |
---|---|---|---|
#8 | menu_link_enabled-2780423-8.patch | 1.97 KB | Bambell |
Comments
Comment #2
acbramley CreditAttribution: acbramley at Department of Justice & Community Safety, Victoria commentedQuickfix for now.
Comment #3
Berdirenabled actually has a default value of TRUE, so we should be able to just remove this?
Comment #4
Bambell CreditAttribution: Bambell at MD Systems GmbH commentedFailing test to expose the bug. Incoming patch...
Comment #7
Bambell CreditAttribution: Bambell at MD Systems GmbH commentedActually, I think that should be done in core as well. Here's how enabled's default value is set :
'#default_value' => (int) (bool) $defaults['id']
So checked if a menu link exists. It seems to me like we can easily know if it's actually enabled or not.
If we remove it completely, then the menu link is disabled each time the node is edited, if the user doesn't explicitly enable it?
Comment #8
Bambell CreditAttribution: Bambell at MD Systems GmbH commentedHere we go.
Comment #9
BerdirThanks, looks good, will commit this soon. Giving @acbramley a chance to verify that this fixes the problem for him as well.
Comment #10
acbramley CreditAttribution: acbramley at Department of Justice & Community Safety, Victoria commentedConfirming it works for me, thanks guys
Comment #12
BerdirThanks for confirming, committed.