How to change order and depth of user account tabs

by xinxin   Last Updated June 18, 2018 12:07 PM

With Tab Tamer we can change the weight/order of tabs in the user account under user/% (e.g. put user/%/edit after user/%/some_settings), but we can't set depth between the tabs (e.g. user/%/some_settings under user/%/edit/some_settings).

With User Tabs we can create some depth at least for user/%/edit (makes it as a subtab of Account), but it doesn't offer options to put other tabs as subtabs of Account.

So how to transform tabs to subtabs in the user account?

Tags : 7 users navigation


Answers 1


I forked User Tabs and added new subtabs (see NEW-SUBTAB in code):

/**
 * Implements hook_menu_alter().
 */
function usertabs_menu_alter(&$callbacks) {
  $callbacks['user/%user/account'] = array(
    'title' => 'Account',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
    'load arguments' => array('%map', '%index'),
  );
  //move the original edit and view items to below this container
  _usertabs_move_item($callbacks, 'user/%user/view', 'user/%user/account/view', MENU_DEFAULT_LOCAL_TASK);
  _usertabs_move_item($callbacks, 'user/%user/edit', 'user/%user/account/edit', MENU_LOCAL_TASK);
  _usertabs_move_item($callbacks, 'user/%user/NEW-SUBTAB', 'user/%user/account/NEW-SUBTAB', MENU_LOCAL_TASK);
  unset($callbacks['user/%user_category/edit/account']);
  if (($categories = _user_categories()) && (count($categories) > 1)) {
    foreach ($categories as $key => $category) {
      // 'account' is already handled by the MENU_DEFAULT_LOCAL_TASK.
      if ($category['name'] != 'account') {
        //it was too friggin complicated to support %user_category
        //see comments in user_category_load
        //all it does is check that the category name is valid
        _usertabs_move_item($callbacks, 'user/%user_category/edit/' . $category['name'], 'user/%user/account/'.$category['name']);
        $callbacks['user/%user/account/'.$category['name']]['tab_parent'] = 'user/%/account';
      }
    }
  }
}
xinxin
xinxin
June 18, 2018 11:50 AM

Related Questions


A specific menu for specific user

Updated July 23, 2016 08:03 AM


Current Username title instead Secondary menu title

Updated October 04, 2016 09:03 AM

Add a menu item programmaticaly

Updated September 05, 2018 10:07 AM

User menu on 404 pages

Updated September 24, 2017 09:07 AM