0

Below I have changed the default tab at /admin to /admin/index, but now /admin/tasks is 403. Even if I change $items['admin/tasks']['access callback'] to TRUE I'm still denied access.

function hook_menu_alter(&$items) {
  $items['admin/tasks']['page callback'] = 'system_admin_menu_block_page';
  $items['admin/tasks']['access arguments'] = $items['admin']['access arguments'];
  $items['admin/tasks']['file'] = $items['admin']['file'];
  $items['admin/tasks']['type'] = MENU_LOCAL_TASK;

  $items['admin']['page callback'] = $items['admin/index']['page callback'];

  $items['admin/index']['type'] = MENU_DEFAULT_LOCAL_TASK;
  unset($items['admin/index']['page callback']);
  unset($items['admin/index']['access arguments']);
  unset($items['admin/index']['file']);
}

How can I both restore access to /admin/tasks and set the default tab to /admin/index?

Resolution: The admin module was the problem. It's enabled by default in my installation profile.

2 Answers 2

0

please find this code to do this

function hook_menu_alter(&$items) {
$a_title = $items['admin']['title'];
$admin = $items['admin'];
$t_title = $items['admin/tasks']['title'];
$tasks = $items['admin/tasks'];
$i_title = $items['admin/index']['title'];
$index = $items['admin/index'];
$items['admin/tasks'] = $admin;
$items['admin/tasks']['title'] = $t_title;
$items['admin/tasks']['type'] = MENU_LOCAL_TASK;
$items['admin'] = $index;
$items['admin']['title'] = $a_title;
unset($items['admin']['type']);
unset($items['admin/index']);
$items['admin/index'] = $tasks;
$items['admin/index']['title'] = $i_title;
}
4
  • There is still the same problem. /admin/tasks denies access.
    – htoip
    Commented Mar 5, 2014 at 13:40
  • after change this code in your module, clear menu cache. Commented Mar 10, 2014 at 12:22
  • Aye, I tried that. Does this code work for you?
    – htoip
    Commented Mar 10, 2014 at 15:36
  • Yes, used the same code, both tabs worked with this code. Commented Mar 11, 2014 at 5:46
0

This is cleaned up some and prevents the admin module from botching /admin/tasks.

/**
 * Implements hook_menu_alter().
 *
 * Change default tab at /admin to that of the index rather than tasks.
 */
function hook_menu_alter(&$items) {
  $items['admin/tasks']['page callback'] = 'system_admin_menu_block_page';
  $items['admin/tasks']['access arguments'] = $items['admin']['access arguments'];
  $items['admin/tasks']['file'] = $items['admin']['file'];
  $items['admin/tasks']['type'] = MENU_LOCAL_TASK;

  $items['admin']['page callback'] = $items['admin/index']['page callback'];

  $items['admin/index']['type'] = MENU_DEFAULT_LOCAL_TASK;
  unset($items['admin/index']['page callback']);

  unset($items['admin/index']['access arguments']);
  unset($items['admin/index']['file']);
  unset($items['admin']['menu_name']);
  // Prevent admin module from taking over in this case, but do not change
  // behavior.
  if (module_exists('admin')) {
    $items['admin/tasks']['access arguments'][] = NULL;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.