0

In my module I need to install custom menu items (add to existing main-menu) on the front-end side. So basically it's a simple one-time operation, yet it rises some questions about the proper way to deal with programatic menu items in general.

  1. hook_install + menu_link_save sounds good for installing the items, hook_uninstall + menu_link_delete - for uninstalling, but how am I supposed to find out the $mlid parameter of the menu link - required by the menu_link_delete function?
  2. Would hook_enable and hook_disable be more suitable?

  3. How do I protect my module's menu items from deleting on the admin UI side?

1 Answer 1

1

You can programatically add/remove menu items on install/uninstall and/or enable/disable events. But that's not how we do usually.

Implement hook_menu and you will be fine to go with almost any menu item implementation.

A few points. Set menu router item's 'type' => MENU_NORMAL_ITEM and it will now be in a menu. Unless you set 'menu_name', it will be placed in the "navigation" menu. See the huge (and very helpful) text on the page. Also, have a look at examples module for high-quality hook_menu examples.

Good luck!

1
  • Thanks Ayesh. Let's see if I'm lucky today. On my bilingual site I try to programatically assign a menu router to a particular language, by adding 'options' => array('language' => 'fr') To no avail. Should this work? Commented Nov 26, 2012 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.