I am developing a custom module that will have the functionality to show a particular menu link active on the desired path. For this I have implemented hook_form_FROM_ID_alter() hook for menu_edit_item(). In the edit form of each menu item there I have provided options similar to block modules page visibility options

  • Active on all pages except listed
  • Active only on listed pages
  • Active depending upon given php code

But I need to match the path listed with any existing path. Do I need to implement other hook or create more functions to implement this or this functionality should be implemented in hook_form_FROM_ID_alter(). I have also created a database table for this that stores

  • menu link ID
  • Visibility (i.e. flag to the option chosen by the user 0, 1, 2)
  • Pages (i.e the paths given by the user in the textarea eg: node/4, etc)

Thanks for your help in advance


1 Answer 1


This is an existing module which does part of what you want to do. The module is Menu item visibility. I recommend looking at how it works and extending it (it says it's extendable) to add the extra pieces you are requesting: visible per page, or visible on PHP code. It probably has hooks you can use to complete your business logic.

In fact, this issue talks about adding "per page" or "php code" conditions essentially.

  • Yeah I have referred that module but this module only provides per role visibility not per page visibility. Just tell me is there any special hook to implement that Mar 28, 2012 at 5:44
  • 1
    From the 7.x-1.x branch of the module. You would create a hook for module_invoke_all('menu_item_visibility_load', $visibility, $mlid); to supply a $visibility array for your FAPI elements to add your custom conditions (page, path, whatever). You would then have to patch function menu_item_visibility_translated_menu_link_alter() to use a hook so that your module can write the business logic to enforce your custom $visibility FAPI widget(s). ... I'm just saying this module does most of what you want, you'd have to help finish that module and learn howto define/implement hooks.
    – tenken
    Mar 29, 2012 at 18:14

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.