1

I'm creating a drop down menu with nice menus, but I'm having a problem programatically adding a link to the menu from modules. I have defined the menu in the Administration section under Site Building > Menus and can get it to work fine if I add a link manually, but I can't get any links from modules to show up. Here is my code from module_menu():

  $items['node/%node/jobs'] = array(
    'title' => 'Jobs',
    'page callback' => 'job_applications_form',
    'page arguments' => array(1, 'node'),
    'access callback' => 'job_applications_user_access',
    'access arguments' => array('site_owner', 1),
    'menu_name' => 'menu-dealer-menu',
    'type' => MENU_NORMAL_ITEM,
  );

The menu's name is menu-dealer-menu. I am using Drupal 6, and upgrading to 7 is not an option right now, and won't be for the next couple of months.

1
  • Well, I couldn't find any way to do this in Drupal 6 so I just ended up creating a custom menu and some functions to make it do what I want. If anyone else runs into this problem, just send me a message and I'll be glad to help.
    – Kyle
    Commented Dec 16, 2011 at 18:03

1 Answer 1

1

You are using a wildcard in the path node/%node/jobs. If you want Drupal to show a menu link, you have to tell it how to figure out the %node argument. You can do it with a function named node_to_arg.

The function name, actually, is [wildcard]_to_arg. I suggest you change the wildcard to something different, since there are several menu paths with %node in it. If you relied on node_load to return you a node object, you can just call it from [wildcard]_load.

There is documentation on [wildcard]_to_arg and you can see how user_uid_optional_to_arg implements it for the user/%user_uid_optional path.

1
  • The Pro Drupal Development explains it very clearly, it's where I learned about it. Give it a try. Commented Dec 23, 2011 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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