Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Eugene Dubois on
I would like to learn a bit of drupal development.
Now I came across hook_menu. Is it possible to add an item to the primary links with this hook?
Thanks,
Eugene
Comments
Sort of
hook_menu adds a menu item to Drupal with a default path/location.
The location of that menu item may (depending on the menu type you give it in the module) be able to be changed by the site admin on the menu admin pages. Also the site admin chooses which menu is the primary links menu.
So you can create a module that creates a menu item, and that menu item can be put in the menu that gets used for the primary links.
--
Anton
Thanks
Thank you for the answer Anton.
What I would like to achieve on my website is, that members with a certain role will get an extra tab in the primary links menu at the top of my page. Is this the best way to do that, or is there an other option?
Eugene
Probably
As far as I know there isn't a contrib module for menu item access control (but I've lost touch with the sheer volume of Drupal modules these days).
If that is the case then yes, creating the menu item yourself in a module would be the best way to control access. hook_menu() allows to to specify a function to be an "access callback" for that menu item:
http://api.drupal.org/api/function/hook_menu/6
--
Anton
Well...
I Just got a primary link added using 'menu_name' in my menu item (i'm using drupal 6):
Then, apply access control on the tab by specifying:
So, something like the following might help you:
Thanks!
Thank you! I was able to get my modules to add to the primary links and only show for the correct permissions after reading this.
Hi, This seems easy enough,
Hi,
This seems easy enough, but it's not working !
I've created a custom module and implemented hook_menu.
I can see the new menu links (xxxxx and zzzzz) in the menu_links and menu_router sql tables. I can see them along with the links I created with admin/build/menus. Unfortunately the Primary Links Block only produces the links from admin/build/menus.
I've cleared the cache, I've rebuild the menus, nothing... :-/
edit : oh, and I've also tried with links that actually exist (node/1, node/2) and tried prefixing primary-links like so : menu-primary-links (saw this in other forums).
edit 2 : I'm also noticing that when I use an existing url (node/1, node/2) the menu_name is forced to "navigation"
Any thoughts?
Cheers
I figured it out
I needed a valid callback. I was expecting the link to appear regardless.