Index: slider_textfield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/slider_textfield/slider_textfield.module,v
retrieving revision 1.3.2.1.2.1
diff -u -p -r1.3.2.1.2.1 slider_textfield.module
--- slider_textfield.module	29 Nov 2008 08:20:29 -0000	1.3.2.1.2.1
+++ slider_textfield.module	23 Dec 2008 00:32:34 -0000
@@ -66,11 +66,15 @@ function slider_textfield_help($path, $a
  * Implementation of hook_elements().
  */
 function slider_textfield_elements() {
-  $type['slider_textfield'] = array(
-    '#attributes' => array('class' => 'slider_textfield'),
-    '#input' => TRUE,
+  return array(
+				'slider_textfield' => array(
+						'#attributes' => array('class' => 'slider_textfield'),
+						'#input' => TRUE,
+						'#columns' => array('value'),
+						'#delta' => 0,
+						'#process' => array('number_process'),
+				),
   );
-  return $type;
 }
 
 /**
@@ -79,8 +83,11 @@ function slider_textfield_elements() {
 function slider_textfield_theme() {
   return array(
     'slider_textfield' => array(
-      'arguments' => array('element' => NULL)
-    )
+      'arguments' => array('element' => NULL),
+    ),
+				'slider_textfield_formatter_slider' => array(
+						'arguments' => array('element' => NULL),
+				),
   );
 }
 
@@ -119,11 +126,15 @@ function theme_slider_textfield($element
   $slider_settings[$element['#id']] = $element['#slider_settings'];
   drupal_add_js(array('slider_settings' => $slider_settings), 'setting');
 
-  $size = $element['#size'] ? ' size="'. $element['#size'] .'"' : '';
+  $maxlength = (empty($element['#maxlength']) ? $element['value']['#maxlength'] : $element['#maxlength']);
+  $value = (empty($element['value']) ? $element['#value'] : $element['value']['#value']);
+
+  $element_size = (empty($element['#size']) ? $element['value']['#size'] : $element['#size']);
+  $size = $element_size ? ' size="'. $element_size .'"' : '';
 
   $output = '';
 
-  $output .= '<input type="hidden" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size .' value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />';
+  $output .= '<input type="hidden" maxlength="'. $maxlength .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size .' value="'. check_plain($value) .'"'. drupal_attributes($element['#attributes']) .' />';
 
   $output .= '<div class="slider_wrapper">';
   $output .= '  <div class="small_label"></div>';
@@ -136,3 +147,132 @@ function theme_slider_textfield($element
 
   return theme('form_element', $element, $output);
 }
+
+/**
+ * Implementation of hook_formatter_info().
+	*/
+function slider_textfield_formatter_info() {
+  $formatters = array();
+		$formatters['slider_textfield'] = array(
+				'label' => 'Slider',
+				'field types' => array('number_integer'),
+		);
+		return $formatters;
+}
+
+function theme_slider_textfield_formatter_slider($element) {
+  $field = $element['#field_name'];
+		$item = $element['#item'];
+
+  $output = '';
+
+  $output .= '<input type="hidden" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size .' value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />';
+
+  $output .= '<div class="slider_wrapper">';
+  $output .= '  <div class="small_label"></div>';
+  $output .= '  <div id="slider_bar_'. $element['#id'] .'" class="slider_bar">';
+  $output .= '    <div class="slider_callout"></div>';
+  $output .= '    <div class="slider_handle"></div>';
+  $output .= '  </div>';
+  $output .= '  <div class="large_label"></div>';
+  $output .= '</div>';
+
+		return $output;
+}
+
+
+/**
+ * Implementation of hook_widget_info().
+	*/
+function slider_textfield_widget_info() {
+		return array(
+				'slider_textfield' => array(
+						'label' => t('Slider'),
+						'field types' => array('number_integer'),
+						'multiple values' => CONTENT_HANDLE_CORE,
+						'callbacks' => array(
+								'default value' => CONTENT_CALLBACK_CUSTOM,
+						),
+				),
+		);
+}
+
+/**
+ * Implementation of hook_widget().
+	*/
+function slider_textfield_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+		$element = array(
+		 	'#type' => $field['widget']['type'],
+		 	'#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
+		);
+  return $element;
+}
+
+/**
+ * Implementation of hook_process().
+	*/
+function slider_textfield_process($element, $edit, $form_state, $form) {
+  $field_name = $element['#field_name'];
+  $field = $form['#field_info'][$field_name];
+  $field_key  = $element['#columns'][0];
+
+  $value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : '';
+  $value = isset($field['decimal']) ? str_replace('.', $field['decimal'], $value) : $value;
+  $element[$field_key] = array(
+    '#type' => 'textfield',
+    '#default_value' => $value,
+    // Need to allow a slightly larger size that the field length to allow
+    // for some configurations where all characters won't fit in input field.
+    '#size' => isset($field['precision']) ? $field['precision'] + 2 : 12,
+    '#maxlength' => isset($field['precision']) ? $field['precision'] : 10,
+    '#attributes' => array('class' => 'number'),
+    // The following values were set by the content module and need
+    // to be passed down to the nested element.
+    '#title' => $element['#title'],
+    '#description' => $element['#description'],
+    '#required' => $element['#required'],
+    '#field_name' => $element['#field_name'],
+    '#type_name' => $element['#type_name'],
+    '#delta' => $element['#delta'],
+    '#columns' => $element['#columns'],
+  );
+
+  $prefixes = array();
+  $suffixes = array();
+
+  // Make sure we don't wipe out element validation added elsewhere.
+  if (empty($element['#element_validate'])) {
+    $element['#element_validate'] = array();
+  }
+  if (!empty($field['prefix'])) {
+    $prefixes = explode('|', $field['prefix']);
+    $element[$field_key]['#field_prefix'] = array_pop($prefixes);
+  }
+  if (!empty($field['suffix'])) {
+    $suffixes = explode('|', $field['suffix']);
+    $element[$field_key]['#field_suffix'] = array_pop($suffixes);
+  }
+  switch ($field['type']) {
+    case 'number_float':
+      $element['#element_validate'][] = 'number_float_validate';
+      break;
+    case 'number_integer':
+      $element['#element_validate'][] = 'number_integer_validate';
+      break;
+    case 'number_decimal':
+      $element['#element_validate'][] = 'number_decimal_validate';
+      $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.';
+      $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10;
+      $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2;
+      break;
+  }
+
+  // Used so that hook_field('validate') knows where to flag an error.
+  $element['_error_element'] = array(
+    '#type' => 'value',
+    '#value' => implode('][', array_merge($element['#parents'], array($field_key))),
+  );
+
+  return $element;
+}
+
