Saving a node with an empty menu link title causes the menu link to silently not be created

Created on 30 August 2012, almost 13 years ago
Updated 12 October 2023, over 1 year ago

If you create a node and check the "Provide a menu link" checkbox but leave the menu link title field blank, then when you save the node no menu link is created - and no error message is printed either.

Although this field is usually auto-filled via JavaScript based on the node title, there are situations where that won't happen (for example, if the node title field is being hidden on the form and generated automatically).

Two possible ways to fix this:

  1. Make the menu link title field conditionally required whenever the "Provide a menu link" checkbox is checked.
  2. If an empty menu link title field is submitted, autogenerate it based on the node title.

The first fix seems like it wouldn't be backportable. So, I wrote patches for the second fix instead.

🐛 Bug report
Status

Fixed

Version

10.1

Component
Menu UI 

Last updated 23 days ago

No maintainer
Created by

🇺🇸United States David_Rothstein

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇱Netherlands Lendude Amsterdam

    This came up as a bug smash triage target.

    Rerolled.

    Fixed the if/else to actually do what it is supposed to do, if the trimmed version of the provided title is empty -> set the title to the node title, in previous versions the trim did nothing.
    We don't need to do the actual trimming since that is already handled by _menu_ui_node_save, so we only need to trim to check we actually end up with a valid title in _menu_ui_node_save.

  • 🇮🇳India nayana_mvr

    Verified the patch #44 and tested it on Drupal version 9.5.x. The patch works fine and I have added the before and after screen recordings for reference.
    Steps followed:-

    • Create any basic page.
    • Click on Menu setting and check on Provide a menu link.
    • Remove the menu title generated automatically based on node title.
    • Save the node.
    • Check Main navigation menu.

    After applying the patch, a menu link corresponding to the new node is autogenerated in the main navigation menu based on the node title even though the menu link title field was empty while creating the node.

  • Status changed to RTBC over 2 years ago
  • 🇺🇸United States smustgrave

    Confirmed the issue on D10.1 by manually deleting the title field for the menu link.
    Applied the patch and did the same steps and the menu link was created.

  • 🇳🇱Netherlands Lendude Amsterdam

    Unrelated fail

    • catch committed 586900ec on 10.1.x
      Issue #1763002 by dcam, idebr, David_Rothstein, marthinal, aerozeppelin...
  • Status changed to Fixed over 2 years ago
  • 🇬🇧United Kingdom catch

    Option #2 seems good. Double checked the test coverage to make sure we actually have test coverage for removing a link, and that's fine.

    I doubt there are lots of people using the bug to remove menu links as opposed to unchecking the checkbox, but going to just commit this to 10.1.x in case.

    Committed 586900e and pushed to 10.1.x. Thanks!

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

  • Status changed to Fixed over 1 year ago
  • 🇩🇪Germany stefan.korn Jossgrund

    This has been a bug so long, it has gotten a feature ... ;-)

    In a project we rely on the old behaviour to realize a special workflow regarding creation of menu links while node editing. Now with the new behavior we have a bc break going from D9 to D10. Yes, I know this can happen going from D9 to D10.

    I am also wondering if there might not be people that just clear the title to remove a menu link and then wonder why they get the menu link back even with different text if they changed the menu title before. And additionaly if you for example edit nodes from the content overview you will not get directed to the node view and might even not realize that this has happened.

    I am not clearly seeing the bug in the old behavior and it was there for a long time ... But surely I have been 10 years to late for lamenting on this, but I really thought this behavior was intended the way it was.

  • 🇩🇪Germany stefan.korn Jossgrund

    I mean this is not straight forward:

    You have save a menu link with different title than the node title.
    You come back later and remove the menu title and save the node.
    You still have the menu link, but now with the node title again.

Production build 0.71.5 2024