views:

36

answers:

3
+1  Q: 

Add Tab in Profile

Hi,

How can I add a tab into my personal profile (/users/my-name)? I used this function, but nothuing shows up:

function tpzclassified_menu() {
  $items['user/%user/kleinanzeigen'] = array(
    'title' => t('Meine Kleinanzeigen'),
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
  );

  return $items;
}

+1  A: 

You're missing the page callback property:

function tpzclassified_menu() {
  $items['user/%user/kleinanzeigen'] = array(
    'title' => t('Meine Kleinanzeigen'),
    'page callback' => 'tpzclassified_kleinanzeigen',
    'page arguments' => array(1),
    'access callback' => 'user_view_access',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
  ); 

  return $items; 
}

function tpzclassified_kleinanzeigen($account) {
  return 'This is the Meine Kleinanzeigen page';
}

Replace tpzclassified_kleinanzeigen with the function name that generates the page.

Also, never use 'access callback' => TRUE: it's a huge security hole. I've changed that to use user_view_access(), which checks to the see if the user is allowed to view %user's profile. You could use user_edit_access() if you wanted to check to see if a user is allowed to edit %user's profile.

Mark Trapp
For the access, it's enough to use `'access arguments' => array('access user profiles')`, and not define `'access callback'`; in that case `user_access()` will be used as access callback. About the page callback, the [documentation]() describes it as "The function to call to display a web page when the user visits the path. If omitted, the parent menu item's callback will be used instead."; the parent menu (`user/%user`) uses `user_page()` as page callback, and that is the reason the new menu doesn't show anything.
kiamlaluno
A: 
Lars
A: 
Lars

related questions