diff --git vertical_tabs.module vertical_tabs.module index ae21797..061b846 100644 --- vertical_tabs.module +++ vertical_tabs.module @@ -36,6 +36,43 @@ function vertical_tabs_form_alter(&$form, $form_state, $form_id) { // The javascript to add to the page. $settings = array(); + + $default_tab = vertical_tabs_default_tab($node_type); + if (strlen($default_tab)) { + $form['vertical_tab_default'] = array( + '#type' => 'fieldset', + '#title' => $default_tab, + '#weight' => -100, + ); + + // list of elements to restrict from the default tab + $restricted_keys = array( + 'buttons', + 'form_build_id', + 'form_token', + 'form_id', + 'nid', + 'vid', + 'uid', + 'created', + 'type', + 'language', + 'changed', + ); + + // Iterate through the form, finding *non* fieldsets. + foreach (element_children($form) as $delta => $key) { + if (!in_array($key, $fieldsets) && + ($key !== 'vertical_tab_default') && + (!isset($form[$key]['#access']) || $form[$key]['#access'] != FALSE) && + !in_array($key, $restricted_keys)) { + $form['vertical_tab_default'][$key] = $form[$key]; + unset($form[$key]); + } + } + array_push($fieldsets, 'vertical_tab_default'); + } + // Iterate through the form, finding fieldsets. foreach (element_children($form) as $delta => $key) { // We need to make sure that the element we have is a fieldset @@ -160,6 +197,12 @@ function vertical_tabs_node_type_form($node_type) { '#collapsed' => TRUE, '#description' => t('The selected fieldsets will be rendered as vertical tabs for this content type. The tabs are rendered in the same version as the original form\'s fieldsets.'), ); + $form['vertical_tabs']['vertical_tabs_default_tab'] = array( + '#type' => 'textfield', + '#title' => t('Name of Default Vertical Tab'), + '#description' => t('Leave blank to keep top level form elements like title and body outside of Vertical Tabs.'), + '#default_value' => vertical_tabs_default_tab($node_type), + ); $form['vertical_tabs']['vertical_tabs_fieldsets'] = array( '#type' => 'checkboxes', '#options' => $fieldsets, @@ -245,6 +288,13 @@ function vertical_tabs_fieldsets($node_type) { } /** + * Retrieve the name of the default tab if it's set. + */ +function vertical_tabs_default_tab($node_type) { + return variable_get('vertical_tabs_default_tab_' . $node_type, ''); +} + +/** * After build function to add vertical tabs JS and CSS to the form. */ function theme_vertical_tabs(&$form_element) { @@ -271,4 +321,4 @@ function theme_vertical_tabs_js_css($js, $css, $settings, $form_id) { } $js_added[$form_id] = TRUE; } -} \ No newline at end of file +}