In Drupal 7, PHP 7 after log-in an user would end-up on the url "site.com/user/1" where 1 is the user id. This url corresponds to the View tab of the user.
I have added a new tab, called "My dashboard" by using the hook_menu, accessed at url site.com/user/1/dashboard. Everything functions well.
However, after the user logs in I would like the My Dashboard tab to be the default one. And I can’t make it work.
I tried with in two ways, both have the same problem
The first way I tried is:
function mymodule_menu() { $items['user/%user/dashboard'] = array( 'title' => t('My dashboard'), 'page callback' => 'mymodule_dashboard', 'page arguments' => array(1), 'access callback' => TRUE, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -20, ); return $items; } function mymenu_menu_alter(&$items){ $items['user/%user/view'] = array( 'type' => MENU_LOCAL_TASK, ); return $items; }
The second way I tried is:
function mymodule_menu_alter(&$items){ $items['user/%user/dashboard'] = array( 'title' => t('My dashboard'), 'page callback' => 'mymodule_dashboard', 'page arguments' => array(1), 'access callback' => TRUE, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -20, ); $items['user/%user/view'] = array( 'type' => MENU_LOCAL_TASK, ); return $items; }
I clear all the time the cache.
The problem is that after login the View tab disappears as name of the tab, "My Dashboard" is the active tab but it has the content of the previous View tab. Here is the picture: https://ibb.co/w0J4xDK Moreover the url after login is site.com/users/myusername1 thus it is not the dahsboard url which is the site.com/user/1/dashboard.
Then when I click between the tabs, the "My dashboard" keeps this wrong URL, site.com/users/myusername1 , and displays the content of the View tab. Thus the problem is not only after log-in.
I tried a few variations between hook_menu and hook_menu_alter, but I can’t make it work…
How can I have "My dashboard" and its own content displayed as the default tab after log in?
Many thanks