? README.txt
? REMOVED.txt
? TODO.txt
Index: vertical_tabs.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vertical_tabs/vertical_tabs.install,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 vertical_tabs.install
--- vertical_tabs.install	18 Nov 2009 20:28:34 -0000	1.1.2.9
+++ vertical_tabs.install	28 Nov 2009 19:17:56 -0000
@@ -7,24 +7,30 @@
  */
 
 /**
- * Implementation of hook_install().
+ * Implement hook_install().
  */
 function vertical_tabs_install() {
   // Make this module's weight heavy so it runs after most form alterations.
   db_query("UPDATE {system} SET weight = 300 WHERE type = 'module' AND name = 'vertical_tabs'");
+}
 
+/**
+ * Implement hook_enable().
+ */
+function vertical_tabs_enable() {
   // Generate color stylesheet.
   vertical_tabs_install_color_generate();
 }
 
 /**
- * Implementation of hook_uninstall().
+ * Implement hook_uninstall().
  */
 function vertical_tabs_uninstall() {
   $node_types = array_keys(node_get_types('names'));
   foreach ($node_types as $node_type) {
     variable_del('vertical_tabs_fieldsets_' . $node_type);
   }
+  variable_del('vertical_tabs_forms');
 }
 
 /**
@@ -69,6 +75,17 @@ function vertical_tabs_update_6103() {
 }
 
 /**
+ * Delete the node type fieldset configurations.
+ */
+function vertical_tabs_update_6104() {
+  $node_types = array_keys(node_get_types('names'));
+  foreach ($node_types as $node_type) {
+    variable_del('vertical_tabs_fieldsets_' . $node_type);
+  }
+  return array();
+}
+
+/**
  * Initialize the color-enabled stylesheet if using Garland.
  */
 function vertical_tabs_install_color_generate() {
Index: vertical_tabs.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vertical_tabs/vertical_tabs.js,v
retrieving revision 1.3.2.16
diff -u -p -r1.3.2.16 vertical_tabs.js
--- vertical_tabs.js	19 Nov 2009 01:30:52 -0000	1.3.2.16
+++ vertical_tabs.js	28 Nov 2009 19:17:56 -0000
@@ -66,14 +66,3 @@ Drupal.behaviors.verticalTabsReload = fu
     }
   });
 }
-
-Drupal.behaviors.verticalTabsSettings = function(context) {
-  $('input#edit-vertical-tabs-fieldsets-vertical-tabs-all', context).click(function () {
-    var checked = $(this).attr('checked');
-    $('fieldset.vertical-tabs-vertical_tabs_settings input:not(#edit-vertical-tabs-fieldsets-vertical-tabs-all):checkbox').attr('checked', checked).attr('disabled', checked);
-  });
-  $(document).ready(function () {
-    var checked = $('input#edit-vertical-tabs-fieldsets-vertical-tabs-all').attr('checked');
-    $('fieldset.vertical-tabs-vertical_tabs_settings input:not(#edit-vertical-tabs-fieldsets-vertical-tabs-all):checkbox').attr('checked', checked).attr('disabled', checked);
-  });
-}
Index: vertical_tabs.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vertical_tabs/vertical_tabs.module,v
retrieving revision 1.1.2.32
diff -u -p -r1.1.2.32 vertical_tabs.module
--- vertical_tabs.module	19 Nov 2009 01:30:52 -0000	1.1.2.32
+++ vertical_tabs.module	28 Nov 2009 19:17:56 -0000
@@ -6,7 +6,7 @@
  */
 
 /**
- * Implementation of hook_theme().
+ * Implement hook_theme().
  */
 function vertical_tabs_theme() {
   return array(
@@ -30,36 +30,48 @@ function vertical_tabs_theme() {
  * @return
  *   TRUE if the vertical tabs were added to the form, otherwise FALSE.
  */
-function vertical_tabs_add_vertical_tabs(&$form, $fieldsets = NULL) {
+function vertical_tabs_add_vertical_tabs(&$form, $included = NULL, $excluded = array()) {
   global $theme;
   $settings = array();
   $weight = 0;
+  $delta = 0;
 
-  // 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
-    // and the user has access to this field.
-    if ((!isset($fieldsets) || in_array($key, $fieldsets)) &&
-      (isset($form[$key]['#type']) && $form[$key]['#type'] == 'fieldset') &&
-      (!isset($form[$key]['#access']) || $form[$key]['#access'] != FALSE)) {
-      // Add the JavaScript.
-      $settings[$key] = array(
-        'name' => $form[$key]['#title'],
-        'weight' => (isset($form[$key]['#weight']) ? $form[$key]['#weight'] : 0) + (0.001 * $delta),
-        'callback' => (isset($form[$key]['#summary_callback']) ? $form[$key]['#summary_callback'] : $key),
-        'args' => (isset($form[$key]['#summary_arguments']) ? $form[$key]['#summary_arguments'] : array()),
-      );
-      // Add a class to identify the fieldset.
-      if (isset($form[$key]['#attributes']['class'])) {
-        $form[$key]['#attributes']['class'] .= ' vertical-tabs-fieldset vertical-tabs-'. $key;
-      }
-      else {
-        $form[$key]['#attributes']['class'] = 'vertical-tabs-fieldset vertical-tabs-'. $key;
-      }
+  // Iterate through the form's fieldset elements.
+  foreach (vertical_tabs_get_form_fieldsets($form) as $key => $title) {
+    // Disregard non-fieldset elements.
+    if (!isset($form[$key]['#type']) || $form[$key]['#type'] != 'fieldset') {
+      continue;
+    }
+    
+    // Disregard fieldsets that are not accessible to the user.
+    if (isset($form[$key]['#access']) && empty($form[$key]['#access'])) {
+      continue;
+    }
+    
+    // Disregard non-included or specified excluded elements.
+    if ((isset($included) && !in_array($key, $incldued)) || in_array($key, $excluded)) {
+      continue;
+    }
+    
+    // Add the JavaScript.
+    $settings[$key] = array(
+      'name' => $form[$key]['#title'],
+      'weight' => (isset($form[$key]['#weight']) ? $form[$key]['#weight'] : 0) + (0.001 * $delta),
+      'callback' => (isset($form[$key]['#summary_callback']) ? $form[$key]['#summary_callback'] : $key),
+      'args' => (isset($form[$key]['#summary_arguments']) ? $form[$key]['#summary_arguments'] : array()),
+    );
 
-      // Track the maximum weight for the vertical tabs element.
-      $weight = max($weight, $settings[$key]['weight']);
+    // Add a class to identify the fieldset.
+    if (isset($form[$key]['#attributes']['class'])) {
+      $form[$key]['#attributes']['class'] .= ' vertical-tabs-fieldset vertical-tabs-'. $key;
+    }
+    else {
+      $form[$key]['#attributes']['class'] = 'vertical-tabs-fieldset vertical-tabs-'. $key;
     }
+
+    // Track the maximum weight for the vertical tabs element and increment delta.
+    $weight = max($weight, $settings[$key]['weight']);
+    $delta++;
   }
 
   // The JavaScript and CSS specific for this form.
@@ -90,7 +102,7 @@ function vertical_tabs_add_vertical_tabs
       '#vertical_tabs_settings' => $settings,
       '#vertical_tabs_js' => $js,
       '#vertical_tabs_css' => $css,
-      '#form_id' => $form['form_id']['#value'],
+      '#form_id' => isset($form['#vertical_tabs']['form_id']) ? $form['#vertical_tabs']['form_id'] : $form['form_id']['#value'],
       '#type' => 'markup',
       '#value' => '',
       '#theme' => 'vertical_tabs',
@@ -103,95 +115,74 @@ function vertical_tabs_add_vertical_tabs
 }
 
 /**
- * Implementation of hook_form_alter.
+ * Remove vertical tabs elements and processing from a form.
  */
-function vertical_tabs_form_alter(&$form, $form_state, $form_id) {
-  // Add our color-handling submit handler to the color settings form.
-  if ($form_id == 'system_theme_settings' && isset($form['color']) && function_exists('gd_info')) {
-    $form['#submit'][] = 'vertical_tabs_color_submit';
+function vertical_tabs_remove_vertical_tabs(&$form) {
+  unset($form['#vertical_tabs']);
+  unset($form['vertical_tabs']);
+  if (isset($form['#pre_render'])) {
+    $form['#pre_render'] = array_diff($form['#pre_render'], array('vertical_tabs_form_pre_render'));
   }
+}
 
+/**
+ * Implement hook_form_alter().
+ */
+function vertical_tabs_form_alter(&$form, $form_state, $form_id) {
+  $config = variable_get('vertical_tabs_forms', array()) + vertical_tabs_get_default_forms();
+  
   // Skip programmed forms when adding vertical tabs.
-  if ($form['#programmed']) {
+  if ($form['#programmed'] || (isset($config[$form_id]) && $config[$form_id] === FALSE)) {
+    vertical_tabs_remove_vertical_tabs($form);
     return;
   }
 
-  // Check to see which form we are in. Since the node form's form id is not
-  // just node_form, we can't implement a function for all node forms, so we are
-  // stuck implementing the global form_alter and checking if there is the
-  // string node_form in the form id.
-  if (substr($form_id, -10) == '_node_form') {
-    $form['#pre_render'][] = 'vertical_tabs_node_form_pre_render';
-  }
-
-  if ($form_id == 'node_type_form' && $form['#node_type']->type) {
-    vertical_tabs_node_type_form($form, $form['#node_type']->type);
-  }
-
-  if ($form_id == 'node_type_form') {
-    vertical_tabs_add_vertical_tabs($form);
-    unset($form['vertical_tabs']['#vertical_tabs_settings']['identity']);
-    drupal_add_js(drupal_get_path('module', 'vertical_tabs') . '/vertical_tabs.node_type_form.js');
+  if (isset($config[$form_id])) {
+    $form['#vertical_tabs'] = is_array($config[$form_id]) ? $config[$form_id] : array();
+    $form['#vertical_tabs']['form_id'] = $form_id;
+    $form['#pre_render'][] = 'vertical_tabs_form_pre_render';
+    
+    // Add supported core forms summary JavaScript.
+    if (substr($form_id, -10) == '_node_form') {
+      drupal_add_js(drupal_get_path('module', 'vertical_tabs') . '/vertical_tabs.node_form.js');
+    }
+    elseif ($form_id == 'node_type_form') {
+      drupal_add_js(drupal_get_path('module', 'vertical_tabs') . '/vertical_tabs.node_type_form.js');
+    }
   }
 }
 
 /**
- * Pre-render function for the node form.
+ * Form pre-render callback; add vertical tabs to the form.
  */
-function vertical_tabs_node_form_pre_render($form) {
-  $node_type = $form['type']['#value'];
-
-  // The $fieldsets array is a list of all supported fieldsets in core
-  // for the node form, and their JavaScript summary creators.
-  $fieldsets = variable_get('vertical_tabs_fieldsets_'. $node_type, array('vertical-tabs-all'));
-  if (in_array('vertical-tabs-all', $fieldsets)) {
-    $fieldsets = NULL;
-  }
-
-  vertical_tabs_add_vertical_tabs($form, $fieldsets);
-  drupal_add_js(drupal_get_path('module', 'vertical_tabs') . '/vertical_tabs.node_form.js');
-
+function vertical_tabs_form_pre_render($form) {
+  if (!isset($form['#vertical_tabs']) || !is_array($form['#vertical_tabs'])) {
+    $form['#vertical_tabs'] = array();
+  }
+  $form['#vertical_tabs'] += array(
+    'form_id' => $form['form_id']['#value'],
+    'exclude' => array(),
+  );
+  vertical_tabs_add_vertical_tabs($form, NULL, $form['#vertical_tabs']['exclude']);
   return $form;
 }
 
-function vertical_tabs_node_type_form(&$form, $node_type) {
-  module_load_include('inc', 'node', 'node.pages');
-
-  // Build a psuedo-node for a sample node form.
-  $node = (object) array(
-    'type' => $node_type,
-    'name' => '',
-    'vid' => 0,
-  );
-
-  // Build a sample node form to find fieldsets.
-  $node_form_state = array('values' => array());
-  $node_form_id = $node_type .'_node_form';
-  $node_form = drupal_retrieve_form($node_form_id, $node_form_state, $node);
-  $node_form['#post'] = $node_form_state['values'];
-  drupal_prepare_form($node_form_id, $node_form, $node_form_state);
-  uasort($node_form, 'element_sort');
-  $available_fieldsets = vertical_tabs_get_form_fieldsets($node_form);
-  $tabbed_fieldsets = variable_get('vertical_tabs_fieldsets_' . $node_type, array('vertical-tabs-all'));
-  if (in_array('vertical-tabs-all', $tabbed_fieldsets)) {
-    $tabbed_fieldsets += $available_fieldsets;
-  }
-
-  $form['vertical_tabs_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Vertical tabs'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $form['vertical_tabs_settings']['vertical_tabs_fieldsets'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Select the fieldsets that should be rendered as vertical tabs for this content type'),
-    '#options' => array('vertical-tabs-all' => t('<strong>All available fieldsets</strong>')) + $available_fieldsets,
-    '#default_value' => $tabbed_fieldsets,
-    '#description' => t('The tabs are rendered in the same order as the original fieldsets.'),
-  );
+/**
+ * Get the default supported forms.
+ */
+function vertical_tabs_get_default_forms() {
+  $forms = array();
+  $node_types = array_keys(node_get_types('names'));
+  foreach ($node_types as $node_type) {
+    $forms[$node_type . '_node_form'] = TRUE;
+  }
+  $forms['node_type_form'] = array('exclude' => array('identity'));
+  return $forms;
 }
 
+/**
+ * Get all the fieldset elements from a form.
+ */
 function vertical_tabs_get_form_fieldsets($form) {
   $fieldsets = array();
   foreach (element_children($form) as $key) {
@@ -203,18 +194,37 @@ function vertical_tabs_get_form_fieldset
 }
 
 /**
- * Implementation of hook_node_type().
+ * Implement hook_node_type().
  */
 function vertical_tabs_node_type($op, $info) {
-  if ($op == 'delete') {
-    variable_del('vertical_tabs_fieldsets_' . $info->type);
+  $config = variable_get('vertical_tabs_forms', array()) + vertical_tabs_get_default_forms();
+  if ($op == 'update' && $info->old_type != $info->type) {
+    $config[$info->type . '_node_form'] = $config[$info->old_type . '_node_form'];
+    unset($config[$info->old_type . '_node_form']);
+    variable_set('vertical_tabs_forms', $config);
+  }
+  elseif ($op == 'delete') {
+    unset($config[$info->old_type . '_node_form']);
+    variable_set('vertical_tabs_forms', $config);
+  }
+}
+
+/**
+ * Implement hook_form_FORM_ID_alter().
+ *
+ * Add our color-handling submit handler to the color settings form.
+ */
+function vertical_tabs_form_system_theme_settings_alter(&$form, $form_state) {
+  // Add our color-handling submit handler to the color settings form.
+  if (isset($form['color']) && function_exists('gd_info')) {
+    $form['#submit'][] = 'vertical_tabs_system_theme_settings_submit';
   }
 }
 
 /**
  * Submit handler for the theme settings page.
  */
-function vertical_tabs_color_submit($form, &$form_state) {
+function vertical_tabs_system_theme_settings_submit($form, &$form_state) {
   $theme = $form_state['values']['theme'];
   $info = $form_state['values']['info'];
 
@@ -291,3 +301,50 @@ function theme_vertical_tabs_js_css($js,
     $js_added[$form_id] = TRUE;
   }
 }
+
+/**
+ * Implement hook_form_controller_info().
+ */
+function vertical_tabs_form_controller_info() {
+  $alterations['vertical_tabs'] = array(
+    'title' => t('Vertical tabs'),
+    'description' => t('Enables fieldsets to be collapsed into a vertical tab dispaly.'),
+    'form callback' => 'vertical_tabs_form_controller_configure',
+  );
+  return $alterations;
+}
+
+function vertical_tabs_form_controller_configure(&$complete_form, $form_id, $context) {
+  if ($fieldsets = vertical_tabs_get_form_fieldsets($context['form'])) {
+    $config = variable_get('vertical_tabs_forms', array()) + vertical_tabs_get_default_forms();
+    $is_form_tabified = isset($context['form']['vertical_tabs']) || (isset($context['form']['#pre_render']) && in_array('vertical_tabs_form_pre_render', $context['form']['#pre_render']));
+    $form['status'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Vertical tabify this form.'),
+      '#default_value' => isset($config[$form_id]) ? $config[$form_id] : $is_form_tabified,
+      '#access' => count($fieldsets),
+    );
+    $form['exclude'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Exclude the following fieldsets'),
+      '#options' => $fieldsets,
+      '#default_value' => isset($config[$form_id]['exclude']) ? $config[$form_id]['exclude'] : array(),
+    );
+    $complete_form['#submit'][] = 'vertical_tabs_form_controller_configure_submit';
+    return $form;
+  }
+}
+
+function vertical_tabs_form_controller_configure_submit($form, &$form_state) {
+  $config = variable_get('vertical_tabs_forms', array()) + vertical_tabs_get_default_forms();
+  $form_id = $form_state['form_controller']['form_id'];
+  if ($form_state['values']['vertical_tabs']['status']) {
+    $config[$form_id] = array(
+      'exclude' => array_values(array_filter($form_state['values']['vertical_tabs']['exclude'])),
+    );
+  }
+  else {
+    $config[$form_id] = FALSE;
+  }
+  variable_set('vertical_tabs_forms', $config);
+}
Index: vertical_tabs.node_form.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vertical_tabs/Attic/vertical_tabs.node_form.js,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 vertical_tabs.node_form.js
--- vertical_tabs.node_form.js	18 Nov 2009 20:06:45 -0000	1.1.2.9
+++ vertical_tabs.node_form.js	28 Nov 2009 19:17:56 -0000
@@ -28,12 +28,12 @@ Drupal.verticalTabs.revision_information
 }
 
 Drupal.verticalTabs.author = function() {
-  var name = $('#edit-name').val(), date = $('#edit-date').val();
+  var author = $('#edit-name').val() || Drupal.t('Anonymous'), date = $('#edit-date').val();
   if (date) {
-    return Drupal.t('By @name on @date', { '@name': name, '@date': date });
+    return Drupal.t('By @name on @date', { '@name': author, '@date': date });
   }
   else {
-    return Drupal.t('By @name', { '@name': name });
+    return Drupal.t('By @name', { '@name': author });
   }
 }
 
