4

I am trying to add two new tabs to the user account page at mysite.com/user on my Drupal 7 site. I want to add links to Add Photos node/add/photos and Add Videos node/add/videos but the following code for my module user_menu_add is not working for me:

function user_menu_add_menu() {

$items['node/add/photos'] = array(
    'title' => t('Add Photos'),
    'page callback' => 'user_menu_add',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'access arguments' => array('access user menu add'),
    'type' => MENU_LOCAL_TASK,
);

return $items;

}

an example i have referenced is here which works but only for links beneath the "/user" sub directory

function my_module_menu() {

$items['user/%user/funky'] = array(
    'title' => t('Funky Button'),
    'page callback' => 'my_module_funky',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'access arguments' => array('access funky button'),
    'type' => MENU_LOCAL_TASK,
);

return $items;

}

Current User Tabs

Community
  • 1
  • 1
Lee Woodman
  • 1,319
  • 2
  • 16
  • 30

2 Answers2

6

You can keep the node/add/photos menu item as is. You need to keep the URL pattern formatting like it is for the user/%user/addphoto in order to make the tab appear on the user profile page. However, try using drupal_goto() in your new menu item to redirect to the node/add/photos page.

Try this:

$items['user/%user/addphoto'] = array(
  'title' => t('Add Photos'),
  'page callback' => 'drupal_goto',
  'page arguments' => array('node/add/photos'),
  'access callback' => 'user_is_logged_in',
  'type' => MENU_LOCAL_TASK,
);

References:

Aiias
  • 4,683
  • 1
  • 18
  • 34
  • Thank you! I could not figure out why Drupal wouldn't route me outside of the user profile area without this! – DrCord Mar 14 '14 at 22:36
6

I haven't enough reputation to comment an answer. Pay attention that hook_menu requires an untranslated title indeed the documentation says:

"title": Required. The untranslated title of the menu item.

so the code should be

function my_module_menu() {
    $items['user/%user/addphoto'] = array(
      'title' => 'Add Photos',
      'page callback' => 'drupal_goto',
      'page arguments' => array('node/add/photos'),
      'access callback' => 'user_is_logged_in',
      'type' => MENU_LOCAL_TASK,
    );
    return $items;
}
lastYorsh
  • 573
  • 7
  • 17
  • You are correct. Specifically the value given as "title" is passed to "title callback" which defaults to [t()](https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7). – Alex Barrett Mar 07 '14 at 15:55