View source
<?php
function tabsexample_menu() {
$items = array();
$items['tabsexample'] = array(
'title' => 'Tabs example, basic',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'tabsexample_form',
),
'access arguments' => array(
'access content',
),
'type' => MENU_NORMAL_ITEM,
);
$items['tabsexample-ajax'] = array(
'title' => 'Tabs example, AJAX',
'page callback' => 'tabsexample_ajax_tabset',
'access arguments' => array(
'access content',
),
'type' => MENU_NORMAL_ITEM,
);
$items['tabsexample/ajax'] = array(
'title' => 'Tabs example ajax',
'page callback' => 'tabsexample_ajax',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function tabsexample_form() {
$form = array();
$form['example1'] = array(
'#type' => 'tabset',
);
$form['example1']['tab1'] = array(
'#type' => 'tabpage',
'#title' => t('One'),
'#content' => t('First tab content.') . theme('item_list', array(
l(t('one'), 'node'),
l(t('two'), 'node'),
l(t('three'), 'node'),
)),
);
$form['example1']['tab2'] = array(
'#type' => 'tabpage',
'#title' => t('Two'),
'#content' => t('Second tab content.'),
);
$form['example1']['tab2']['tabset2'] = array(
'#type' => 'tabset',
);
$form['example1']['tab2']['tabset2']['tab1'] = array(
'#type' => 'tabpage',
'#title' => t('One'),
'#content' => t('First tab content.'),
);
$form['example1']['tab2']['tabset2']['tab2'] = array(
'#type' => 'tabpage',
'#title' => t('Two'),
);
$form['example1']['tab2']['tabset2']['tab2']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
$form['example1']['tab3'] = array(
'#type' => 'tabpage',
'#title' => t('Three'),
'#content' => t('Third tab content.'),
'#selected' => TRUE,
);
return $form;
}
function tabsexample_ajax_tabset() {
$tabset = array();
$tabset['my_tabset'] = array(
'#type' => 'tabset',
);
$tabset['my_tabset']['first_tab'] = array(
'#type' => 'tabpage',
'#title' => t('One'),
'#content' => t('First tab content.'),
);
$tabset['my_tabset']['second_tab'] = array(
'#type' => 'tabpage',
'#title' => t('Two--Ajax loaded'),
'#ajax_url' => url('tabsexample/ajax'),
);
$tabset['my_tabset']['third_tab'] = array(
'#type' => 'tabpage',
'#title' => t('Three'),
);
return tabs_render($tabset);
}
function tabsexample_ajax() {
echo t('Sample content loaded via AJAX.');
}