It would be handy if we could generate menus and menu links. It would help themers test menu depths, etc.

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new6.79 KB

Patch attached that adds menu generation with configurable menus, existing menus to add links to, link title length, link types, menu depth, and deleting existing generated menus.

moshe weitzman’s picture

Status: Needs review » Needs work

code looks great to me. only issues i can think of are:

* ORDER BY RAND() is a performance killer. can we figure a way to get rid of those?
* drush integration

johnalbin’s picture

Regarding the ORDER BY RAND(), I tried adding 400 menu links to the main menu and it took less then 4 seconds for the whole response page to load. And it turns out that 400 menu links was a stupid crazy amount of links to add because it made the primary links like 30 items wide. So I don't think ORDER BY RAND() will be an issue for normal sized menu tree generation.

moshe weitzman’s picture

You are assuming that folks run this on am empty site. The ORDER BY RAND are on menu_links and node tables. Both can get pretty big, in my experience.

mr.baileys’s picture

Status: Needs work » Needs review
StatusFileSize
new9.96 KB

Here's an attempt to skip "ORDER BY RAND()" by loading the list of potential parent items once, and picking random plids using array_rand(). Array is kept up to date when adding menu items.

Also added drush integration. Disclaimer: first time writing a drush command...

moshe weitzman’s picture

Er, load every menu link into memory? That sounds like a pig. The best way I have found to avoid ORDER BY RAND() is documented at http://www.electrictoolbox.com/msyql-alternative-order-by-rand/. I did it in drupal somewhere but i can't find where. If folks can't get that to work, then we can leave it as dave posted. I notice now that we already have several order by rand() so i'm less picky.

johnalbin’s picture

StatusFileSize
new13.74 KB

I've been working on Dave's patch in #1, cleaning up the UI and making the generated tree be a little more manageable.

  1. ORDER BY RAND() has been replaced by the proper orderRandom() DBTNG method.
  2. Added a maximum width option to make the first level of links be a certain width.
  3. Made the UI for creating new menus and/or choosing menus slightly more intuitive.
  4. Made it possible to delete devel-generated links added to existing menus.
  5. Fixed a bug preventing the selection of link types to work.
  6. Fixed a bug in the link depth form api.
  7. Updated the drush integration from #5 to include max_width and default values.
johnalbin’s picture

StatusFileSize
new13.83 KB

Menu links pointing to nodes now use the node title as the menu title.

johnalbin’s picture

StatusFileSize
new12.58 KB

Ok. Just discovered form api #states. And I've converted the js to a #states array.

moshe weitzman’s picture

Tried this out and it works well.

It looks like the drush integration can only generate new menus and not add links to existing menus. Is that by design? Would be nice if we said what the default values were in the drush help for each argument.

Is there any way that we can just rely on menu.inc and not menu.module? Or is core so screwed up that we have important APIs in the .module?

johnalbin’s picture

hmm… creating custom menus is limited to menu.module. And menu_get_menus() is a menu.module function. Let me review and see what I can do.

johnalbin’s picture

StatusFileSize
new12.88 KB

Okay, I've added some code so that the "create new menus" option is hidden when the menu module is disabled. Basically, I've wrapped if (module_exists('menu')) around any code that needs it.

As for the drush stuff, I just copied it from the earlier patch. It does need work, but there are too many options to make it really useful for me to type all that stuff in at the command line; so I have no real interest in learning drush internals to flesh out that code.

moshe weitzman’s picture

FYI, drush has a 'drupal dependencies' key in a command definition where you can list required modules.

dave reid’s picture

Let's just declare a dependency on the menu.module. You can't go in and inspect/edit individual items without it installed, so I think it makes sense that we require it.

johnalbin’s picture

Assigned: dave reid » Unassigned

Moshe and Dave, I think you might have cross-posted with my latest patch.

The patch in #12 doesn't need menu module enabled. If it isn't enalbed, then devel limits itself to generating menu links in system-provided menus. If menu is enabled, it provides the option to generate new menus and to generating menu links in menu-module-created menus.

Also, if the existing drush implementation in the patch is insufficient, I'm fine with ripping it out until someone goes to write a more full-featured one. Again, I have no need for such functionality. Scratch your own itch, etc. :-)

moshe weitzman’s picture

Status: Needs review » Fixed

Committed. I added defaults to the drush argument descriptions.

Thanks.

Status: Fixed » Closed (fixed)

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

jacine’s picture

OMG, this is so amazing! You guys are the best. Thank you so much :D

R-H’s picture

Getting an issue with the machine name when using the drush generate menus command

The machine-readable name must contain only lowercase letters, numbers, and hyphens.

Drush prepends "devel_" to the machine menu name, which is invalid.

So my menu name is "devel_randomstring".

moshe weitzman’s picture

fixed machine name

R-H’s picture

Where is the generate menus functionality? Has it been committed to D6 (6.x-1.x-dev) or just D7?

Anonymous’s picture

available to 6.X ?

johnalbin’s picture

Just to D7, not in D6.