You are here

function range_process in Range 6

Process an individual element.

Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.

The $fields array is in $form['#field_info'][$element['#field_name']].

1 string reference to 'range_process'
range_elements in ./range.module
Implementation of FAPI hook_elements().

File

./range.module, line 468
Defines numeric fields within a range of possible values and displays them colored accordingly..

Code

function range_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' => 'range',
    ),
    // 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();
  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 'range_float':
      $element['#element_validate'] = array(
        'range_float_validate',
      );
      break;
    case 'range_integer':
      $element['#element_validate'] = array(
        'range_integer_validate',
      );
      break;
    case 'range_decimal':
      $element['#element_validate'] = array(
        'range_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,
    ))),
  );

  //adding range settings to the element so the theme_range_formatter_generic() function can be overriden with the theme_range() function

  //$field_settings = unserialize(db_result(db_query("SELECT global_settings from {". content_field_tablename() ."} where field_name = '%s'", $element['#field_name'])));

  //$element['#field_settings'] = $field_settings;
  return $element;
}