--- checkall.module	2009-06-19 07:16:30.000000000 -0400
+++ checkall.module.NEW	2009-08-05 15:24:14.000000000 -0400
@@ -17,18 +17,40 @@ function checkall_form_alter(&$form, $fo
  * After build callback.
  */
 function checkall_form_after_build($elements, &$form_state) {
-  checkall_form_after_build_recursive($elements);
+  checkall_form_after_build_recursive($elements, $form_state);
   return $elements;
 }
 
 /**
+ * Control '#checkall' attribute in CCK form field definition.
+ */
+function checkall_widget_settings_alter(&$v, $op, $widget) {
+  if ($widget['type'] == 'optionwidgets_buttons' || $widget['widget_type'] == 'optionwidgets_buttons') {
+    switch ($op) {
+      case 'form':
+        $v['checkall'] = array(
+          '#type' => 'checkbox',
+          '#title' => t('Include checkall option'),
+          '#default_value' => isset($widget['checkall']) ? $widget['checkall'] : 0,
+          '#description' => t('Select this to display a checkall option near checkbox groups.'),
+          '#weight' => 2,
+        );
+        break;
+      case 'save':
+        $v = array_merge($v, array('checkall'));
+        break;
+    }
+  }
+}
+
+/**
  * Helper function to find elements with '#checkall' attribute recursively.
  */
-function checkall_form_after_build_recursive(&$elements, $checkall = NULL) {
+function checkall_form_after_build_recursive(&$elements, &$form_state, $checkall = NULL) {
   foreach (element_children($elements) as $key) {
     if (isset($elements[$key]) && $elements[$key]) {
-      $children_checkall = (isset($checkall) ? $checkall : (!empty($elements[$key]['#checkall']) ? $elements[$key]['#checkall'] : NULL));
-      checkall_form_after_build_recursive($elements[$key], $children_checkall);
+      $children_checkall = ((empty($element['#checkall']) && isset($form_state['#field_info'])) ? $form_state['#field_info'][$elements[$key]['#parents'][0]]['widget']['checkall'] : (isset($checkall) ? $checkall : (!empty($elements[$key]['#checkall']) ? $elements[$key]['#checkall'] : NULL)));
+      checkall_form_after_build_recursive($elements[$key], $form_state, $children_checkall);
     }
   }
   if (isset($checkall) && isset($elements['#type']) && $elements['#type'] == 'checkboxes') {
