[development] Display a custom menu by code in hook install

Daniel Caillibaud ml at lairdutemps.org
Sat May 9 14:45:23 UTC 2009


Hi,

In a module of my own, I build a custom menu, but I don't see how I could enabled it in my install hook. Is it possible ?

My code is, in hook install :
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')",
    'mymenu', t('Test menu'), t("My own menu tree for testing purpose."));

in hook menu :
[...]
  $items['mymenu1'] = array (
    'title' => t('Entrée root 1'),
    'page callback' => 'mymenu_test',
    'page arguments' => array (0),
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'mymenu',
    'expanded' => TRUE,
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
  );
[...]

With this code, I have my custom menu, but I still need to activate it manually in admin/build/block. I can't call db_query on
blocks table in my hook install because block doesn't exist yet.
Is there a clean solution ? (creating a block entry with sql query in hook install doesn't sounds very nice).

Should I have to replace all my items in hook menu and my custom menu by menu_link_save calls (under navigation menu tree) in
hook install? 

Thanks

-- 
Daniel


More information about the development mailing list