BDR
BDR

Reputation: 464

Drupal 7 : Create tabs in configuration page

I have created a module with a configuration page, everything works well, but my configuration page seems endless. So would like to create tabs as in the configuration page of comments :

https://i.sstatic.net/Penba.png

I've search a lot and tried to analyse the comments module code unsuccessfully :

Can someone help me to do that or at least give me a lead ?

Thanks in advance, BDR

Upvotes: 1

Views: 2493

Answers (1)

Nebel54
Nebel54

Reputation: 1338

You need to implement hook_menu for your module. I can recommend you the great examples module from drupal.org which has really great examples for most aspects of extending drupal. This code is taken from the menu_example submodule of the example module:

function mymodule_menu(){
  // A menu entry with tabs.
  // For tabs we need at least 3 things:
  // 1. A parent MENU_NORMAL_ITEM menu item (examples/menu_example/tabs in this
  //    example.)
  // 2. A primary tab (the one that is active when we land on the base menu).
  //    This tab is of type MENU_DEFAULT_LOCAL_TASK.
  // 3. Some other menu entries for the other tabs, of type MENU_LOCAL_TASK.
  $items['examples/menu_example/tabs'] = array(
    // 'type' => MENU_NORMAL_ITEM,  // Not necessary since this is the default.
    'title' => 'Tabs',
    'description' => 'Shows how to create primary and secondary tabs',
    'page callback' => '_menu_example_menu_page',
    'page arguments' => array(t('This is the "tabs" menu entry.')),
    'access callback' => TRUE,
    'weight' => 30,
  );

  // For the default local task, we need very little configuration, as the
  // callback and other conditions are handled by the parent callback.
  $items['examples/menu_example/tabs/default'] = array(
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'title' => 'Default primary tab',
    'weight' => 1,
  );

  $items["examples/menu_example/tabs/second"] = array(
    'type' => MENU_LOCAL_TASK,
    'title' => 'Second tab',
    'page callback' => '_menu_example_second_page',
    'access callback' => TRUE,
    'weight' => 2,      
  );

  return $items;
}

Upvotes: 5

Related Questions