Expands a weight element into a select element.
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;
}