Download & Extend

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

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:

  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.

Comments

#1

Status:active» needs review

Here are patches for Drupal 7 and 8.

AttachmentSizeStatusTest resultOperations
menu-empty-link-title-1763002-1-D7-do-not-test.patch742 bytesIgnoredNoneNone
menu-empty-link-title-1763002-1.patch769 bytesIdleFAILED: [[SimpleTest]]: [MySQL] 40,332 pass(es), 1 fail(s), and 0 exception(s).View details | Re-test

#2

Status:needs review» needs work

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

#3

Status:needs work» needs review

An updated patch for Drupal 8

AttachmentSizeStatusTest resultOperations
menu-empty-link-title-1763002-3.patch798 bytesIdleFAILED: [[SimpleTest]]: [MySQL] 41,107 pass(es), 1 fail(s), and 0 exception(s).View details | Re-test

#4

Status:needs review» needs work

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

#5

Status:needs work» needs review

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.

AttachmentSizeStatusTest resultOperations
d8-menu-empty-link-validate-1763002-5.patch890 bytesIdleFAILED: [[SimpleTest]]: [MySQL] 40,178 pass(es), 239 fail(s), and 260 exception(s).View details | Re-test

#6

Status:needs review» needs work

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

#7

Status:needs work» needs review

At localhost it works so I try again.

AttachmentSizeStatusTest resultOperations
d8-menu-empty-link-validate-1763002-7.patch887 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 41,238 pass(es).View details | Re-test

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

AttachmentSizeStatusTest resultOperations
empty-menu-link-title-1763002-8-tests-only.patch884 bytesIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch empty-menu-link-title-1763002-8-tests-only_0.patch. Unable to apply patch. See the log in the details link for more information.View details | Re-test
empty-menu-link-title-1763002-8.patch1.73 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch empty-menu-link-title-1763002-8_0.patch. Unable to apply patch. See the log in the details link for more information.View details | Re-test

#9

#8: empty-menu-link-title-1763002-8.patch queued for re-testing.

#10

Status:needs review» needs work

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

#11

Status:needs work» needs review

#8: empty-menu-link-title-1763002-8-tests-only.patch queued for re-testing.

#12

Rerolled #8.

AttachmentSizeStatusTest resultOperations
empty-menu-link-title-1763002-12-tests-only.patch888 bytesIdleFAILED: [[SimpleTest]]: [MySQL] 52,246 pass(es), 2 fail(s), and 0 exception(s).View details | Re-test
empty-menu-link-title-1763002-12.patch1.7 KBIdlePASSED: [[SimpleTest]]: [MySQL] 52,254 pass(es).View details | Re-test

#13

Status:needs review» reviewed & tested by the community

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.

AttachmentSizeStatusTest resultOperations
empty-menu-link-title-1763002-12-before.png36.65 KBIgnoredNoneNone
empty-menu-link-title-1763002-12-after1.png75.07 KBIgnoredNoneNone
empty-menu-link-title-1763002-12-after2.png57.56 KBIgnoredNoneNone

#14

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.

nobody click here