In Drupal 7After logging in, PHP 7 after log-in an userusers would end-up on the url "site.com/user/1" where 1 is the user id. This url correspondsbe redirected to the View tab of thetheir user profile page.
I
I have added a new tab, called "My dashboard" byMy dashboard using the hook_menu, accessed at url site.com/user/1/dashboardhook_menu()
. Everything functions well.
However, afterAfter the user logsusers log in, I would like the My Dashboard tabthey are redirected to be the default one. AndMy dashboard, but I can't make it work.
I tried with in two ways, which both have the same problem.
The first wayFirst I tried is:with this code.
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;
}
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 wayThen, I tried is:with the following code.
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;
}
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 timealso cleared the cache.
The problem is that after login, the ViewView tab disappears as name of the tab, "My Dashboard" is the active tab, but it has the content of the previous ViewView tab. Here is the picture: https://ibb.co/w0J4xDK Moreover the url
The URL after the login is site.com/users/myusername1 thus it is not the dahsboard urlhttps://example.com/users/myusername1, which isisn't the site.com/user/1/dashboarddashboard URL.
Then when When I click between the tabs, the "My dashboard"My dashboard keeps this wrong URL, site.com/users/myusername1 , and displays the content of the View*View tab. Thus the problem is not only after log-in.
I tried a few variations between hook_menuhook_menu()
and hook_menu_alterhook_menu_alter()
, but I can't make it work...
How can I have "My dashboard"My dashboard and its own content displayed as the default tab after log inlogin?
Many thanks