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.

CommentFileSizeAuthor
#45 1763002-after-patch.mov8.83 MBnayana_mvr
#45 1763002-before-patch.mov7.94 MBnayana_mvr
#44 1763002-44.patch1.59 KBLendude
#44 interdiff-1763002-37-44.txt669 bytesLendude
#39 After Patch 1763002.png341.43 KBchetanbharambe
#39 Before Patch 1763002.png346.57 KBchetanbharambe
#37 1763002-37.patch1.66 KBAbhijith S
#29 interdiff.txt603 byteswturrell
#29 saving_a_node_with_an-1763002-29.patch1.56 KBwturrell
#27 1763002-26.patch1.46 KBaerozeppelin
#27 test-only-fail-1763002-26.patch686 bytesaerozeppelin
#20 1763002-20.patch1.69 KBidebr
#20 interdiff-20-18.txt2.21 KBidebr
#20 1763002-20.fail_.patch894 bytesidebr
#18 1763002-18.patch735 bytesidebr
#13 empty-menu-link-title-1763002-12-before.png36.65 KBandymartha
#13 empty-menu-link-title-1763002-12-after1.png75.07 KBandymartha
#13 empty-menu-link-title-1763002-12-after2.png57.56 KBandymartha
#12 empty-menu-link-title-1763002-12-tests-only.patch888 bytesdcam
#12 empty-menu-link-title-1763002-12.patch1.7 KBdcam
#8 empty-menu-link-title-1763002-8-tests-only.patch884 bytesdcam
#8 empty-menu-link-title-1763002-8.patch1.73 KBdcam
#7 d8-menu-empty-link-validate-1763002-7.patch887 bytesmarthinal
#5 d8-menu-empty-link-validate-1763002-5.patch890 bytesmarthinal
#3 menu-empty-link-title-1763002-3.patch798 bytesvaibhavjain
#1 menu-empty-link-title-1763002-1-D7-do-not-test.patch742 bytesDavid_Rothstein
#1 menu-empty-link-title-1763002-1.patch769 bytesDavid_Rothstein
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Status: Active » Needs review
FileSize
769 bytes
742 bytes

Here are patches for Drupal 7 and 8.

Status: Needs review » Needs work

The last submitted patch, menu-empty-link-title-1763002-1.patch, failed testing.

vaibhavjain’s picture

Status: Needs work » Needs review
FileSize
798 bytes

An updated patch for Drupal 8

Status: Needs review » Needs work

The last submitted patch, menu-empty-link-title-1763002-3.patch, failed testing.

marthinal’s picture

Status: Needs work » Needs review
FileSize
890 bytes

Here another option.We are inside a form alter so we could add a little validation.I think is better than write something (title) automatically by default because maybe the user in this case has no reference whats going on exactly.

Status: Needs review » Needs work

The last submitted patch, d8-menu-empty-link-validate-1763002-5.patch, failed testing.

marthinal’s picture

Status: Needs work » Needs review
FileSize
887 bytes

At localhost it works so I try again.

dcam’s picture

This needed a test. There was already a test case for a blank menu link title, so I added a couple of asserts to it. They check that we're redirected to the node edit page and the validation error message appears.

This was my first attempt at adding to a test, so constructive criticism is welcome.

dcam’s picture

Issue tags: -Needs backport to D7

Status: Needs review » Needs work

The last submitted patch, empty-menu-link-title-1763002-8.patch, failed testing.

dcam’s picture

Status: Needs work » Needs review
Issue tags: +Needs backport to D7
dcam’s picture

andymartha’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
57.56 KB
75.07 KB
36.65 KB

On a fresh installation of Drupal 8.x-dev on March 8, 2013, I can confirm that the problem of no menu link is created - and no error message is printed either after following the steps in summary. See screenshot.
After applying the patch empty-menu-link-title-1763002-12.patch in #12 by dcam, I can confirm that the patch worked by the form not submitting but showing the proposed error messages nicely. See screenshot.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs review

I think if we're going with option #1 from the issue summary it should be conditionally required in the standard way (i.e., it should get the red asterisk which all other required fields get, and the error message should be worded the same way too)?

I still prefer option #2 personally... This only happens under rare circumstances, and while I guess it is a bit of magic, the user already clicked on a checkbox saying they wanted a menu link so we can just give them a sensible one based on the form they submitted. If they really don't like the title, they can go back and edit it.

The last submitted patch, 12: empty-menu-link-title-1763002-12.patch, failed testing.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll
idebr’s picture

Component: menu.module » menu_ui.module
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
735 bytes

I agree with David_Rothstein falling back to the node title makes more sense than conditionally validating the menu title for the same reason the menu link is prefilled with the node title.

If a menu link is a required field, it should have the #required attribute. The problem with this approach is that the States API can not yet conditionally validate required fields.

I created a new patch based on the #2 proposed resolution.

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Seems like adding a quick test or assertion to MenuNodeTest here would be worthwhile.

The last submitted patch, 20: 1763002-20.fail_.patch, failed testing.

jhedstrom queued 20: 1763002-20.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 20: 1763002-20.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

aerozeppelin’s picture

Rerolling patch #20.

aerozeppelin’s picture

Status: Needs work » Needs review
FileSize
686 bytes
1.46 KB

The last submitted patch, 27: test-only-fail-1763002-26.patch, failed testing.

wturrell’s picture

Partial review (needs someone else to RTBC)

- Reproduced original problem (8.2.x)
- Patch fixes it
- No UI changes
- coding style fine
- All seems to be in scope
- Tests passed and test modified for functional change

The comment above the altered test was out of date, I've updated it.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Abhijith S’s picture

Patch #29 can't be applied.Needs reroll.

Checking patch core/modules/menu_ui/menu_ui.module...
Hunk #1 succeeded at 335 (offset -36 lines).
Checking patch core/modules/menu_ui/src/Tests/MenuNodeTest.php...
error: core/modules/menu_ui/src/Tests/MenuNodeTest.php: No such file or directory
Abhijith S’s picture

Rerolled patch #29 .Please check

Lan’s picture

@Abhijith S the patch seems not working for D9

chetanbharambe’s picture

Status: Needs review » Needs work
FileSize
346.57 KB
341.43 KB

Hi @Abhijith S,
Verified and tested patch #37.
Patch applied successfully and not working as expected

Testing Steps:
# Goto: Appearance -> Apply Seven theme
# Create any basic page
# Click on Menu setting and check on Provide a menu link
# Save the node
# Check the result

Expected Results:
# Check the Two possible ways to fix this which are mentioned in the issue summary and it should be working as per requirement.

Actual Results:
# Currently, No message is appearing before and after applying the patch

Please refer attached screenshots for the same.
Not working as expected.
Can be a move to Needs Work.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Lendude’s picture

Status: Needs work » Needs review
Issue tags: +Bug Smash Initiative
FileSize
669 bytes
1.59 KB

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.

nayana_mvr’s picture

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.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 44: 1763002-44.patch, failed testing. View results

Lendude’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated fail

  • catch committed 586900ec on 10.1.x
    Issue #1763002 by dcam, idebr, David_Rothstein, marthinal, aerozeppelin...
catch’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

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!

Status: Fixed » Closed (fixed)

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

stefan.korn’s picture

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.

stefan.korn’s picture

I mean this is not straight forward:

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