Same name and namespace in other branches
- 7.x-1.x vertical_tabs_example/vertical_tabs_example.module \vertical_tabs_example_form_alter()
Implement hook_form_alter().
Adds custom fieldset to the node form, and attach ajax behaviour for vertical panels to update the settings description.
Related topics
File
- vertical_tabs_example/
vertical_tabs_example.module, line 43 - Shows how to integrate your custom node options with vertical tabs module in Drupal 6. This example does not cover how to save / load custom setting, and only deals with elements visibility.
Code
function vertical_tabs_example_form_alter(&$form, $form_state, $form_id) {
// Only include on node add/edit forms.
if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {
// Define a fieldset for our settings in the node edit form.
$form['vertical_tabs_example'] = array(
'#type' => 'fieldset',
'#title' => t('Example vertical tab'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
// The #group value must be defined to be included in the vertical tabs
// element by default.
'#group' => 'additional_settings',
// Attach the javascript for vertical tabs. Normally we would use
// drupal_add_js(), but the vertical tabs module supports this special
// Drupal 7 #attached property.
'#attached' => array(
'js' => array(
drupal_get_path('module', 'vertical_tabs_example') . '/vertical_tabs_example.js',
),
),
'#tree' => TRUE,
'#weight' => -2,
);
// This checkbox is used to show or hide the custom settings form using
// javascript (altering states of a container defined later).
$form['vertical_tabs_example']['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Use custom configuration'),
'#default_value' => FALSE,
);
// This container will be used to store the whole form for our custom
// settings. This way, showing/hidding the form using javascript is easier,
// as only one element should be set visible.
$form['vertical_tabs_example']['vertical_tabs_examplecontainer'] = array(
'#type' => 'fieldset',
'#title' => t('Custom setting'),
// This attribute is required for vertical tabs to track elements beneath
// it's own tree.
'#parents' => array(
'vertical_tabs_example',
),
);
// The string of this textfield that will be shown as summary in the
// vertical tab if the checkbox is enabled.
$form['vertical_tabs_example']['vertical_tabs_examplecontainer']['custom_setting'] = array(
'#type' => 'textfield',
'#title' => t('Use this custom setting'),
'#default_value' => '',
);
}
}