function form_process_weight
Expands a weight element into a select element.
Related topics
1 call to form_process_weight()
- FormElementTestCase::testWeightDefaultValue in modules/
simpletest/ tests/ form.test - Tests Weight form element #default_value behavior.
1 string reference to 'form_process_weight'
- system_element_info in modules/
system/ system.module - Implements hook_element_info().
File
-
includes/
form.inc, line 4158
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';
$weights = array();
for ($n = -1 * $element['#delta']; $n <= $element['#delta']; $n++) {
$weights[$n] = $n;
}
if (isset($element['#default_value'])) {
$default_value = (int) $element['#default_value'];
if (!isset($weights[$default_value])) {
$weights[$default_value] = $default_value;
ksort($weights);
}
}
$element['#options'] = $weights;
$element += element_info('select');
}
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.