When adding a menu ( admin/structure/menu/add ) you get the machine name from the title input field, using misc/machine-name.js. The actual machine name that is stored in the database adds 'menu_' as a prefix to the visible machine name on the form though (as visible if you save the menu and then edits it to see the machine name).

My thought is that an extra string argument 'prefix' could be added to the call to Drupal.behaviors.machineName.attach that will be added to the machine name, then the menu module could be updated to send 'menu' as a prefix when calling machineName.attach ($form['menu_name'] in menu.admin.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

FreddieK’s picture

Here's a patch that does what's outlined above:

(not working, see next comment)

FreddieK’s picture

I noticed that the patch has the unlucky result that 'menu-' now gets added twice to the machine name, so no disco. But is the approach a good one or should this be solved in a different way?

FreddieK’s picture

Fixed patch.

joachim’s picture

Version: 7.8 » 7.x-dev
Status: Active » Needs work

This seems like a good idea, but this new key needs to be added to the documentation for Drupal.behaviors.machineName.

Some other points:

+++ b/misc/machine-name.js
@@ -111,8 +111,14 @@ Drupal.behaviors.machineName = {
+    ¶

Remember to trim whitespace.

+++ b/misc/machine-name.js
@@ -111,8 +111,14 @@ Drupal.behaviors.machineName = {
     return source.toLowerCase().replace(rx, settings.replace).substr(0, settings.maxlength);

This needs indenting.

+++ b/modules/menu/menu.admin.inc
@@ -556,8 +557,6 @@ function menu_delete_menu_confirm_submit($form, &$form_state) {
-  // 'menu-' is added to the menu name to avoid name-space conflicts.

Move this comment to the 'prefix' item, as the reason we need a prefix still needs explaining.

4 days to next Drupal core point release.

FreddieK’s picture

Updated patch.

Bathie’s picture

Hello, I tested the patch, it is good

mgifford’s picture

Status: Needs work » Needs review

Pushing to needs review. I think that's what's missing here.

Status: Needs review » Needs work

The last submitted patch, add_menu_machine_name-1288910-5.patch, failed testing.

Rajender Rajan’s picture

Rajender Rajan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 9: add-menu-machine-name-1288910-9.patch, failed testing.

tinko’s picture

Status: Needs work » Needs review
FileSize
519 bytes

Hello,

In misc/machine-name.js has a short documentation about the properties and there is already field_prefix that will show before menu name if the #field_prefix is added to field "menu_name".

Greetings

ethomas08’s picture

Is this issue the same as this one?? https://www.drupal.org/project/drupal/issues/2021571
The patch for the other issue looks good. It adds the menu- to the menu name when adding a new menu.

poker10’s picture