function form_process_weight

Expands a weight element into a select element.

Related topics

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

File

drupal/core/includes/form.inc, line 4391
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 = config('system.site')
    ->get('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');
  }
  else {
    $element['#type'] = 'number';

    // Use a field big enough to fit most weights.
    $element['#size'] = 10;
    $element += element_info('number');
  }
  return $element;
}