Display a custom menu by code in hook install
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
Le 09/05/09 à 16:45, Daniel Caillibaud <ml@lairdutemps.org> a écrit :
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 ?
hook_enable seems to be what I need. This function do the job, but if you have a better advice, feel free to post it ;-) function mymenu_enable() { // check if dhtml menu is installed $dhtml = variable_get('dhtml_menu_menus', NULL); if ($dhtml != NULL && is_array($dhtml['menu'])) { $dhtml['menu']['mymenu'] = 1; variable_set('dhtml_menu_menus', $dhtml); } $theme = variable_get('theme_default',''); // weight is hardcoded here, OK for my needs but it should be improved return db_query("UPDATE {blocks} SET theme='$theme', status=1, weight=-10, region='left', title='My test menu' WHERE module='menu' AND delta ='mymenu';"); } -- Daniel
participants (1)
-
Daniel Caillibaud