Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In my module.install file, I have:
$menu = array(
'menu_name' => 'nux_conf',
'title' => $t('NUX Config'),
'description' => $t('NUX User items.'),
);
menu_save($menu);
Following these steps:
- Enable the module
- Disable the module
- Try to delete the menu created from the menu admin page, I get the issue below.
Error: The machine-readable name must contain only lowercase letters, numbers, and hyphens.
The "menu_name" box is in red, but disabled. I'm unable to edit the menu name. I have to go to the database tables and update the name in two tables. I'm then able to delete the menu.
Comment | File | Size | Author |
---|---|---|---|
#18 | menu-names-phpdoc-993134.patch | 540 bytes | lyricnz |
#15 | menu-names-phpdoc-993134.patch | 539 bytes | lyricnz |
#13 | menu-names-phpdoc-993134.patch | 533 bytes | lyricnz |
#5 | menu-names-phpdoc-993134.patch | 495 bytes | lyricnz |
#3 | invalid_menu_names_993134_3.patch | 869 bytes | lyricnz |
Comments
Comment #1
tazzytazzy CreditAttribution: tazzytazzy commentedOh, and the uninstall fails too:
Comment #2
adam.hammouda CreditAttribution: adam.hammouda commentedThe menu_save function now throws an exception if you attempt to save an uninitialized, unnamed or invalidly named menu. This seems to be the appropriate behavior to take in this case - as something akin to drupal_set_message(..., 'error') would not terminate the menu creation process (and modifying the method definition to return a TRUE/FALSE would not seem inline with currently established drupal conventions.)
Comment #3
lyricnz CreditAttribution: lyricnz commentedI can reproduce this issue.
Really pedantic thing: I presume you copied the regex from menu_edit_menu(), but if we're just looking for valid/invalid, we don't need to match > 1 character, so you don't need the '+' in the regex. That's the only change in this patch.
Also, even with the exception thrown, this doesn't actually stop the module being enabled.
Comment #4
lyricnz CreditAttribution: lyricnz commentedAfter discussing this with the community, we felt that this was a classic case of garbage-in => garbage-out (which Drupal explicitly doesn't validate). The correct solution to this situation is to document the valid format of menu_name.
Comment #5
lyricnz CreditAttribution: lyricnz commentedAttached a phpdoc change that describes the valid characters.
Comment #6
lyricnz CreditAttribution: lyricnz commentedCNR
Comment #7
lyricnz CreditAttribution: lyricnz commentedJust so we're clear, I'm no longer supporting being more defensive about the parameters to menu_save(), just more explicit about what is allowed in the phpdoc, especially since it's not a classic "machine name" (which is alpha-numeric plus underbar).
Comment #8
cafuego CreditAttribution: cafuego commentedMakes sense to me.
Comment #9
scor CreditAttribution: scor commented#5: menu-names-phpdoc-993134.patch queued for re-testing.
Comment #10
webchickComment #11
webchickMoving to the documentation queue for review.
Is the description there sufficient? I'm not sure if we use regex patterns elsewhere for describing allowed values. I'm fine with it, since it's developer-facing text, but just want to make sure we're being consistent.
Comment #12
jhodgdonI don't know of any other examples of using regexp in function docblocks, and would prefer it to be written out in words.
Comment #13
lyricnz CreditAttribution: lyricnz commentedComment #14
jhodgdonBetter!
A few little things to fix:
a) - is a hyphen, not a dash. I don't think you need to put the character '-' in there if you call it a hyphen.
b) Drupal punctuation standards: list of 3 items has , before the 'and'. So: apples, bananas, and oranges.
c) Maybe say "composed of lowercase letters..." (add "composed of") and leave out the "only"?
Comment #15
lyricnz CreditAttribution: lyricnz commentedYou have no idea how little I care about this issue :)
Comment #16
jhodgdonhyphen -> hyphens and it is done... thanks for caring enough to at least make a new patch! :)
Comment #17
jhodgdonfixing title to reflect what we're actually doing here
Comment #18
lyricnz CreditAttribution: lyricnz commentedComment #19
jhodgdonThanks! That's good now.
7.x/8/x please...
Comment #20
lyricnz CreditAttribution: lyricnz commentedFYI the text in the UI (D6) that corresponds to this validation is "This name must contain only lowercase letters, numbers, and hyphens, and must be unique."
Comment #21
jhodgdonWell, the d7 text in your patch also includes the word "unique", so I think we've covered it.
Comment #22
webchickCommitted to 8.x and 7.x. Thanks!