'Vertical tabs example', 'description' => 'Shows how vertical tabs can best be supported by a custom module', 'page callback' => '_vertical_tabs_example_explanation', 'access callback' => TRUE, ); return $items; } /** * Implement hook_form_alter(). * * Adds custom fieldset to the node form, and attach ajax behaviour for vertical * panels to update the settings description. */ 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' => '', ); } } /** * Simple explanation page. */ function _vertical_tabs_example_explanation() { return t("The Vertical Tabs Example shows how a custom module can best support vertical tabs. To see the effects of this module, look at the node/add form", array('!node_add' => url('node/add'))); } /** * @} End of "defgroup vertical_tabs_example". */