diff --git a/includes/form.inc b/includes/form.inc index e0bc9cba0b2d5c3e5879e345d4ca6d8c4ce5073a..52eb10bc9defd9f202010d5e209d4d614fbd9354 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -3786,13 +3786,27 @@ function theme_password($variables) { * Expand weight elements into selects. */ function form_process_weight($element) { - for ($n = (-1 * $element['#delta']); $n <= $element['#delta']; $n++) { - $weights[$n] = $n; - } - $element['#options'] = $weights; - $element['#type'] = 'select'; $element['#is_weight'] = TRUE; - $element += element_info('select'); + + // 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; } diff --git a/modules/system/system.module b/modules/system/system.module index d0a542efb0eb428f85f865efe8dcf2c6d06f48f8..46ec87db1f1048d5ff23d9d55a2fdd30263cf03a 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -45,6 +45,13 @@ */ define('DRUPAL_REQUIRED', 2); +/** + * Maximum number of values in a weight select element. + * + * If the number of values is over the maximum, a text field is used instead. + */ +define('DRUPAL_WEIGHT_SELECT_MAX', 100); + /** * Return only visible regions. *