Hi,

I want create in my module, a block that contain a menu like the menu in the navigation block. I tried to implement the hook_menu(). The problem is that only create menu item in the user's navigation block.

Does anyone tried to do something like this ?

Comments

q0rban’s picture

You can create a new menu in admin/menu/menu/add, and then configure all your menu items that you created using hook_menu() to show up in that menu.. then enable the new menu in admin/block..

Hope that answered your question...

cheers

mhtrinh’s picture

Cooool !

I think I understand the trick. I implement my hook_menu() normally, then I create independently an new Menu (eg : My module menu) and finally, I move the menu created by the the hook_menu() in the "My module menu".

That is exactly what I wanted ! Thanks a lot :-)

dreed47’s picture

You can actually do this all in the hook_menu(). You can create your custom menu with code like this:

      $items[] = array(
         'path'        => 'mypath', 
         'title'       => t('My Module Menu'),
         'pid'         => 0,
         'type'        => MENU_CUSTOM_MENU
         );

And then create your normal menu items under your new path:

      $items[] = array(
         'path'        => 'mypath/mysubpath', 
         'title'       => t('My first menu item')
         );
mhtrinh’s picture

I try your code and it works. Then by mistake I go to the admin/menu and Disable the "My first menu item" :-(

Now I can't enable it (it doesn't show in the admin/menu any more, strange ...) . Meanwhile the link to mypath/mysubpath still works ....

Edit : after 30min .... I found that the "My first menu item" is set as disable (normal ...) but in the Navigation Menu, not in the "My Module Menu". Strange bug of drupal .....

Edit 2 : this system ( MENU_CUSTOM_MENU ) is not included in the drupal API ?

heine’s picture

http://drupaldocs.org/api/head/file/includes/menu.inc says:

MENU_CUSTOM_MENU - Custom menus are those defined by the administrator. Reserved for internal use; do not return from hook_menu() implementations.

--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

dreed47’s picture

Your working in 4.6. The code I gave you is not likley to work at all in 4.6.

As Heine pointed out, in 4.7 it's not recommended but I can tell you from experience it works. BUT STILL, use it at your own risk.

heine’s picture

Because drupaldocs.org always defaults to head, I accidentally posted the 4.7 link. But it's the same for 4.6. The value exists but it's not for use...

(4.7 == great!)
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

mhtrinh’s picture

For the "MENU_CUSTOM_MENU" I was blind .... :-p
But the 'pid' field in the hook_menu I don't think to see it somewhere .... detail anyway.

Thanks all of you for your fast help ! I can do now what I wanted :-)