Skip to main content
inlined the image
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

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

screenshot

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

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

After logging in, users would be redirected to their user profile page. I have added a new tab, My dashboard using hook_menu(). Everything functions well.

After the users log in, I would like they are redirected to My dashboard, but I can't make it work.

I tried with in two ways, which both have the same problem.

First I tried 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;
}

Then, I tried 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;
}

I also cleared the cache.

The problem is that after login, the View tab disappears as tab, "My Dashboard" is the active tab, but it has the content of the previous View tab.

screenshot

The URL after the login is https://example.com/users/myusername1, which isn't the dashboard URL. When I click between the tabs, the My dashboard keeps this wrong URL and displays the content of the *View tab.

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 login?

Source Link
MMT
  • 41
  • 6

Change default user tab

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