14

since two hours im trying to create tabs in my custom modules backend.

I've tried severals suggestions but couldn't get any of them to work.

this is my current hook_menu() :

    function social_links_menu() {
  $items['admin/config/system/social_links'] = array(
    'title' => 'social_links',
    'description' => 'Configure to fit clients needs',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('social_links_settings'),
    'access arguments' => array('administer site configuration'),
    'file' => 'social_links.admin.inc',
  );

  return $items;
}

I simply want two tabs called: 'tab1' and 'tab2'.

Can someone give me an working example? This should be really simple, but right now it seems impossible

44

You need to define a 'root' path which is a normal menu item, and then add another item for each of the tabs. The first of these will inherit the properties of the root item, and the second will define its own callbacks.

Combined with the MENU_LOCAL_TASK and MENU_DEFAULT_LOCAL_TASK type constants, you should get the tabs you expect:

function social_links_menu() {
  $items['admin/config/system/social_links'] = array(
    'title' => 'social_links',
    'description' => 'Configure to fit clients needs',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('social_links_settings'),
    'access arguments' => array('administer site configuration'),
    'file' => 'social_links.admin.inc',
  );

  $items['admin/config/system/social_links/tab1'] = array(
    'title' => 'Tab 1',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10
  );

  $items['admin/config/system/social_links/tab2'] = array(
    'title' => 'Tab 2',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'some_callback',
    'access arguments' => array('some permission')
  );

  return $items;
}
  • 2
    thanks for the lesson clive! Good explanation. You just saved me a few hours :) – mhmdrupal Jul 17 '12 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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