By mhtrinh on
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
Create a new menu
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
It works !
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 :-)
do it in one step
You can actually do this all in the hook_menu(). You can create your custom menu with code like this:
And then create your normal menu items under your new path:
Menu item doesn't show up ...
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 ?
http://drupaldocs.org/api/head/file/includes/menu.inc says:
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.
oops
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.
Also in 4.6
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.
Thanks to all :-)
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 :-)