Posted by David_Rothstein on August 30, 2012 at 3:37am
6 followers
| Project: | Drupal core |
| Version: | 8.x-dev |
| Component: | menu.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
| Issue tags: | needs backport to D7 |
Issue Summary
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:
- Make the menu link title field conditionally required whenever the "Provide a menu link" checkbox is checked.
- 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.
Comments
#1
Here are patches for Drupal 7 and 8.
#2
The last submitted patch, menu-empty-link-title-1763002-1.patch, failed testing.
#3
An updated patch for Drupal 8
#4
The last submitted patch, menu-empty-link-title-1763002-3.patch, failed testing.
#5
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.
#6
The last submitted patch, d8-menu-empty-link-validate-1763002-5.patch, failed testing.
#7
At localhost it works so I try again.
#8
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.
#9
#8: empty-menu-link-title-1763002-8.patch queued for re-testing.
#10
The last submitted patch, empty-menu-link-title-1763002-8.patch, failed testing.
#11
#8: empty-menu-link-title-1763002-8-tests-only.patch queued for re-testing.
#12
Rerolled #8.
#13
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.
#14
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.