[support] tutorial on dynamically generating menu in D5

Ivan Sergio Borgonovo mail at webthatworks.it
Mon Jul 28 22:46:23 UTC 2008


On Mon, 28 Jul 2008 10:16:37 -0700
"Metzler, David" <metzlerd at evergreen.edu> wrote:

> The reason that these menus is because a.) they appear in the if
> (!$may_cache) section of the hook_menu and b.) thay are wrapped in
> an if ($user !== FALSE) condition.  

> Note that there is also a separate /user path registered in the if
> ($may_cache) section of the hook_menu. This is the "default" path
> for /user and what shows up in the admin/menu screen. 

did you mean swap($may_cache,!$may_cache)?

I didn't notice the (!may_cache) section since what I'd expect to be
a
$items[] = array('path' => 'user' ...
is actually written as
if ($_GET['q'] == 'user'
Why?

> You may be grappling with one of the core troubles with Drupal 5.
> Oif ($_GET['q'] == 'user'nly menus that are in the if ($may_cache)
> section of the module may be moved around with the admin/menu user
> interface.  If it's a
> dynamic menu, you just don't see it there.  So if you make a

The "My account" hook is defined as MENU_DYNAMIC_ITEM in the
$may_cache section... Does it works as expected because once a user
is logged in cache can't be used?

> dynamic menu item, you can't turn around and move it into a
> block.  Although you may be able to move a the static parent menu

Do you mean "I can't put it into a block with the admin interface"?
If I had a
path=>'root' in $may_cache
and a
path=>'root/otherstuff' in !$may_cache
do you mean I won't see the later?
Wouldn't it be enough to just define
path=>'root/otherstuff'
as MENU_DYNAMIC_ITEM
and place it in the $may_cache section?

That should just make it "locked" (MENU_MODIFIABLE_BY_ADMIN = 0)

> item (defined in the if ($may_cache) section of the menu into a
> separate menu and menu block. This took me a little time to grok.

I didn't get what I can and what I can't do.
eg. I can't add a menu with the admin interface and place it into a
block if it is defined in the !$may_cache

> Finally you can't have the code define a new menu, but only create
> a menu tree section in code and then move it later using the admin
> menu interface. 

What does it mean I can't have code defining a new menu?
I can actually define conditionally a menu tree even in the
$may_cache section.
I didn't see user.module calling menu_rebuild but eg. taxonomy_menu
rebuild the menu when the taxonomy hook is fired.
When does the menu_rebuild have to be called if I have dynamic
menu?

I won't just have to deal with menu appearing and disappearing
according to access but also on other conditions.
eg. if I'd like to dynamically create a menu "See this list" just
when the user (even anonymous user) has some item in the list?
What if I want to change at which depth I want to start to render a
menu in a block?
eg.
a
 a1
  a11
   a111

->

  a11
   a111

or

 a1
  a11
   a111
or

 a1
  a11

etc...
   
Then what is the difference between defining a menu DYNAMIC or
placing it in the !$may_cache section?

MENU_DYNAMIC_ITEM is used just 2 times in core.


> Is that clearing any of this up for you? 

Not completely.

> 2)
> I can't yet understand the magic that make -My account appear in
> the Menu admin pages as locked. I still haven't had the time to
> read the code.

grep -R locked | grep menu solved partially the mystery.
A DYNAMIC menu is not MENU_MODIFIABLE_BY_ADMIN.
But still it doesn't explain what is the difference
between !$may_cache and MENU_DYNAMIC_ITEM

> 3)
> I miss how I can *render* menu with the admin interface and/or in
> modules.
> I'd expect that if I build up a $items hierarchy I could build up
> a menu from the "admin" interface adding a path and the menu
> system will take care of rendering children once I eg. put the
> menu in a block. What if I'd like to render the menu inside my
> code? I think I should use menu_tree... but well I bet there are a
> lot of tricks I could learn without guessing them from the API.

Still didn't get it.
As you said... if at least a parent is in the $may_cache system I
could use the admin interface to add a block that contain a
hierarchy even if some sub menu may be dynamic or in the !$may_cache
section. Is it?
What if all my menu is dynamic? How can I place a menu in a block?

> 4) I haven't seen any tutorial, handbook... on any of the menu_
> family of function.
> There is nothing on "Pro Drupal development" book.

Still reading the api... but it seems that this part of Drupal lack
tutorials, examples or books that explain how to use it.
I checked twice "Pro Drupal Dev" and I didn't find anything
interesting about dynamic menu, there is nothing even in the cache
section.
I gave a quick look to "Learning D6 module development" but it
doesn't seem to contain any useful info on this topic.

thanks

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it



More information about the support mailing list