By intropedro on
I am developing a module which creates a menu with several items. Each item has a field called menu_name where you put the name of the menu where the item will.
his works when I put the name there of menus that already exist or menus that I create by hand before: primary-links secondary-links navigation or menu-MENU_NAME_CREATED.
But what if I want the module to create a menu and put the items him there?
How do I create a menu?
function mymodule_menu(){
$items = array();
$items['parent/item1'] = array(
'title' => t('My item 1'),
'page callback' => 'mymodule_item1',
'page arguments' => array(1),
'access arguments' => array('view mymodule'),
'menu_name' => 'menu-mynewmenu',
'type' => MENU_NORMAL_ITEM,
);
$items['parent/item2'] = array(
'title' => t('My item 2'),
'page callback' => 'mymodule_tem2',
'page arguments' => array(1),
'access arguments' => array('view mymodule'),
'menu_name' => 'menu-mynewmenu',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
Comments
By
By
drupal_execute('menu_edit_menu', bla-bla). There's an example in the first comment here.table menu_custom
You can also directly insert the menu name into the menu_custom table. Have a look at what admin_menu does:
During install, it adds the menu
and then it can add the items to this menu.