1 form.inc form_process_weight($element)

Expands a weight element into a select element.

Related topics

File

core/includes/form.inc, line 4790
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.
  if ($element['#delta'] <= BACKDROP_WEIGHT_SELECT_MAX) {
    $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'] = 'number';
    // Use a field big enough to fit most weights.
    $element['#max'] = 1000000;
    $element += element_info('number');
  }

  return $element;
}