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

Daniel Caillibaud ml at lairdutemps.org
Sat May 9 17:24:48 UTC 2009


Le 09/05/09 à 16:45, Daniel Caillibaud <ml at 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


More information about the development mailing list