How can I create second-level (sub) tabs that will show up on the main user account page. I have used the following code to successfully make a menu tab show up with the other tabs (View | Edit | My New Menu Item), but I need my new menu item to show up as a sub-tab under the main (View) page like the profile categories show up under the Edit tab. I hope this makes sense. I have spent the day reading and searching and can not make it work.

My current code:

function my_module_menu() {
  $items['user/%user/blog'] = array(
    'title' => 'My blog',
    'page callback' => 'my_module_blog_redirect',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
  );
  
  return $items;
}

Any ideas on how to make this instead show up as a sub-tab under the user account 'view' page is greatly appreciated!

Thanks~

Comments

kishorevaishnav’s picture

Whatever you have done is good enough to create an menu and to have submenus for that you need to extend the main menu, so look at the below code to get more clear idea.

<?php
function my_module_menu() {

  $items['user/%user/blog'] = array(
    'title' => 'My blog',
    'page callback' => 'my_module_blog_redirect_submenu1',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
  );

  $items['user/%user/blog/submenu1'] = array(
    'title' => 'My blog Submenu1',
    'page callback' => 'my_module_blog_redirect_submenu1',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );

  $items['user/%user/blog/submenu2'] = array(
    'title' => 'My blog Submenu2',
    'page callback' => 'my_module_blog_redirect_submenu2',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
  );

  $items['user/%user/blog/submenu3'] = array(
    'title' => 'My blog Submenu3',
    'page callback' => 'my_module_blog_redirect_submenu3',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
  );

  return $items;

}
?>

Hope you will flush the cache and test.

zorroposada’s picture

I was wondering how to add submenu tabs on my custom module's page. It is not working for me.

I am doing this:

<?php
  $items['cart/admin'] = array(
    'title' => 'Cart Administration',
    'page callback' => 'cart_admin_home_page',
    'access arguments' => array('access cart admin pages'),
  );
  
  $items['cart/admin/home'] = array(
    'title' => 'Admin\'s Home',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  
  $items['cart/admin/home/subtab'] = array(
    'title' => 'Subtab',
    'page callback' => 'cart_admin_home_page',
    'access arguments' => array('access cart admin pages'),
	'type' => MENU_LOCAL_TASK,
  );
?>

The Subtab is not showing.

I have flushed the menu cache thousand times but nothing.

pfournier’s picture

You have to give an access callback and/or an access argument to each of your second level local tasks (even the default local task).

AaronBauman’s picture

you could also define a hook_user categories operation.
whatever categories you return in such an operation will be added as second level local tasks.
check out simplenews module for an example of how this is done.

farald’s picture

Having the same problem.
Subscribing

EDIT: Not anymore the code above worked

alex.skrypnyk’s picture

The idea behind this is to create a parent Primary local task menu item with path somepath/sometask1 and then create secondary local task menu items by specifying
somepath/primary-task-path/subtask1-path
somepath/primary-task-path/subtask2-path
somepath/primary-task-path/subtask3-path

Drupal will convert specified path to Secondary local task if Primary local task, which starts with the same path, exists.

Software Engineer | DrevOps| www.drevops.com