Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal programmatically adding an item to a menu

I wish to conditionally add an item to a menu. I have a custom module and a menu called "links". How would I add an item to a menu in my module code?

like image 856
Sally Avatar asked Aug 13 '26 22:08

Sally


1 Answers

You need to implement hook_menu in your module. Example:

<?php
function mymodule_menu() {
  $items['mymodule/links'] = array(
    'title' => 'Links', 
    'page callback' => 'mymodule_links_page', 
    'access arguments' => array('access content'), 
    'type' => MENU_SUGGESTED_ITEM,
  );
  return $items;
}
?>

The 'type' => MENU_SUGGESTED_ITEM, part makes it optional, so it can be enabled by the end user - is that what you meant with "conditionally"? If not, please explain what kind of "conditionally" you're looking for.

like image 174
marcvangend Avatar answered Aug 15 '26 19:08

marcvangend