Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

E.g. article has main menu as default, I want to add (and remove) second menu as available to article content type in my unit tests, how can I do it?

share|improve this question

In your hook_menu and set 'access callback' to custom function. In this function return your $node->type == 'my_node_type' and/or user type that can access this node...

share|improve this answer
I meant add second menu on node edit form (available menu list) – drupality Jan 17 '13 at 15:10
up vote 0 down vote accepted

Anyway I win with my lazyness and read Menu module source, you can add menu to available menus list of selected node like:

$type = 'article';
$curr_list = variable_get('menu_options_'.$type);
variable_set('menu_options_'.$type, array_merge($curr_list, array('new_menu')):
share|improve this answer
Neat, though is this more of a hack or is this the way you're supposed to do it? I feel like going through the variable table isn't, err, "normal". – Lester Peabody Jan 17 '13 at 17:06
@LesterPeabody there is no another way probably, anyway it is only for my unit test, after that you can clean up all those things – drupality Jan 17 '13 at 17:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.