I'm currently writing a module and I want to make a stand alone admin menu item.

I wrote my hook_menu like this:


function foobar_menu() {
  $items['admin/foobar'] = array(
    'title' => 'Foobar Admin',
    'description' => 'Foobar related administration tasks',
    'page callback' => 'foobar_admin',
    'access callback' => 'user_access',
    'access arguments' => array('administer foobar'),
    'description' => 'View and administer all the foobar.',
    'file' => 'includes/admin.inc.php',
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/foobar/child'] = array(
    'title' => 'Foobar Child Task',
    'description' => 'Child administration task',
    'page callback' => 'mailnews_admin_child',
    'access callback' => 'user_access',
    'access arguments' => array('administer foobar'),
    'description' => 'View and administer all the foobar child.',
    'file' => 'includes/admin.inc.php',
    'type' => MENU_LOCAL_TASK,
  );

  return $items;
}

I expected the "Foobar Child Task" to appear, as a tab, on the "Foobar Admin" page, But the task didn't show up. Did I got anything wrong? Please help.

Thanks.

Koala Yeung

Comments

nevets’s picture

The tab page needs the same root path as the "main" page it relates to.

yookoala’s picture

In this case, I expect admin/foobar would be the "main" page of admin/foobar/child. But that is not the result.

jaypan’s picture

For the tabs to be rendered, you need a minimum of two tabs, and one of them has to be of type MENU_DEFAULT_LOCAL_TASK. You only have one, and this is why your tab is not rendering. Add this:

  $items['admin/foobar/first'] = array(
    'title' => 'First Child',
    'description' => 'Child administration task',
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );

Contact me to contract me for D7 -> D10/11 migrations.

yookoala’s picture

Problem fixed. Thanks!