Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By 3CWebDev on
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
Extend the menu
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.
Hope you will flush the cache and test.
Sub menu tabs
I was wondering how to add submenu tabs on my custom module's page. It is not working for me.
I am doing this:
The Subtab is not showing.
I have flushed the menu cache thousand times but nothing.
Give access
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).
another way: categories op
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.
Same
Having the same problem.
Subscribing
EDIT: Not anymore the code above worked
The idea behind this is to
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