Index: options_element.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/options_element/options_element.inc,v
retrieving revision 1.9
diff -u -p -r1.9 options_element.inc
--- options_element.inc	18 Oct 2010 01:30:15 -0000	1.9
+++ options_element.inc	28 Dec 2010 19:28:47 -0000
@@ -8,11 +8,10 @@
 
 
 /**
- * Theme an options element.
+ * Pre render an options element
  */
-function theme_options($variables) {
-  $element = $variables['element'];
-
+function pre_render_options($element, $form_state) {
+  // Add classes to the class array.
   $classes = array();
   if (isset($element['#attributes']['class'])) {
     $classes = $element['#attributes']['class'];
@@ -32,41 +31,67 @@ function theme_options($variables) {
   if (isset($element['#multiple']) && $element['#multiple']) {
     $classes[] = 'options-multiple';
   }
+  $element['#attributes']['class'] = $classes;
+
+
+  $element['options'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Options'),
+    '#collapsible' => FALSE,
+    '#attributes' => array('class' => array('options')),
+  );
+
+  $element['options']['custom_keys'] = $element['options_field'];
+  unset($element['options_field']);
 
-  $options = '';
-  $options .= drupal_render($element['options_field']);
   if (isset($element['default_value_field'])) {
-    $options .= drupal_render($element['default_value_field']);
+    $element['options']['default_value_field'] = $element['default_value_field'];
+    unset($element['default_value_field']);
   }
 
-  $settings = '';
+  $element['settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Option settings'),
+    '#attributes' => array('class' => array('option-settings')),
+  );
+
+  $settings = array();
   if (isset($element['custom_keys'])) {
-    $settings .= drupal_render($element['custom_keys']);
+    $settings['custom_keys'] = $element['custom_keys'];
+    unset($element['custom_keys']);
   }
   if (isset($element['multiple'])) {
-    $settings .= drupal_render($element['multiple']);
+    $settings['multiple'] = $element['multiple'];
+    unset($element['multiple']);
   }
   if (isset($element['option_settings'])) {
-    $settings .= drupal_render($element['option_settings']);
+    $settings['option_settings'] = $element['option_settings'];
+    unset($element['option_settings']);
   }
 
-  $output = '';
-  $output .= '<div class="' . implode(' ', $classes) .'">';
-  $output .= theme('fieldset', array('element' => array(
-    '#title' => t('Options'),
-    '#collapsible' => FALSE,
-    '#children' => $options,
-    '#attributes' => array('class' => array('options')),
-  )));
-
-  if (!empty($settings)) {
-    $output .= theme('fieldset', array('element' => array(
+  if (count($settings) > 0) {
+    $element['settings'] = array(
+      '#type' => 'fieldset',
       '#title' => t('Option settings'),
       '#collapsible' => FALSE,
       '#children' => $settings,
       '#attributes' => array('class' => array('option-settings')),
-    )));
+    );
+    $element['settings'] = array_merge($element['settings'], $settings);
   }
+
+  return $element;
+}
+
+/**
+ * Theme an options element.
+ */
+function theme_options($variables) {
+  $element = $variables['element'];
+
+  $output = '';
+  $output .= '<div class="' . implode(' ', $element['#attributes']['class']) .'">';
+  $output .= drupal_render_children($element);
   $output .= '</div>';
 
   return $output;
