function form_process_weight

7.x form.inc form_process_weight($element)
8.x form.inc form_process_weight($element)

Expands a weight element into a select element.

Related topics

1 string reference to 'form_process_weight'
system_element_info in drupal/modules/system/system.module
Implements hook_element_info().

File

drupal/includes/form.inc, line 3992
Functions for form and batch generation and processing.

Code

function form_process_weight($element) {
  $element['#is_weight'] = TRUE;

  // If the number of options is small enough, use a select field.
  $max_elements = variable_get('drupal_weight_select_max', DRUPAL_WEIGHT_SELECT_MAX);
  if ($element['#delta'] <= $max_elements) {
    $element['#type'] = 'select';
    for ($n = (-1 * $element['#delta']); $n <= $element['#delta']; $n++) {
      $weights[$n] = $n;
    }
    $element['#options'] = $weights;
    $element += element_info('select');
  }
  // Otherwise, use a text field.
  else {
    $element['#type'] = 'textfield';
    // Use a field big enough to fit most weights.
    $element['#size'] = 10;
    $element['#element_validate'] = array('element_validate_integer');
    $element += element_info('textfield');
  }

  return $element;
}