Commit 3610fd93 authored by Dries's avatar Dries

- Patch #1519720 by Niklas Fiekas: Remove element_validate_integer() and...

- Patch #1519720 by Niklas Fiekas: Remove element_validate_integer() and element_validate_integer_positive() in favor of the new number element type.
parent 62a39c9a
......@@ -4134,11 +4134,10 @@ function form_process_weight($element) {
}
// Otherwise, use a text field.
else {
$element['#type'] = 'textfield';
$element['#type'] = 'number';
// Use a field big enough to fit most weights.
$element['#size'] = 10;
$element['#element_validate'] = array('element_validate_integer');
$element += element_info('textfield');
$element += element_info('number');
}
return $element;
......@@ -4388,26 +4387,6 @@ function _form_set_class(&$element, $class = array()) {
}
}
/**
* Form element validation handler for integer elements.
*/
function element_validate_integer($element, &$form_state) {
$value = $element['#value'];
if ($value !== '' && (!is_numeric($value) || intval($value) != $value)) {
form_error($element, t('%name must be an integer.', array('%name' => $element['#title'])));
}
}
/**
* Form element validation handler for integer elements that must be positive.
*/
function element_validate_integer_positive($element, &$form_state) {
$value = $element['#value'];
if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) {
form_error($element, t('%name must be a positive integer.', array('%name' => $element['#title'])));
}
}
/**
* @} End of "defgroup form_api".
*/
......
......@@ -66,12 +66,12 @@ function text_field_settings_form($field, $instance, $has_data) {
if ($field['type'] == 'text') {
$form['max_length'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Maximum length'),
'#default_value' => $settings['max_length'],
'#required' => TRUE,
'#description' => t('The maximum length of the field in characters.'),
'#element_validate' => array('element_validate_integer_positive'),
'#min' => 1,
// @todo: If $has_data, add a validate handler that only allows
// max_length to increase.
'#disabled' => $has_data,
......@@ -224,10 +224,10 @@ function text_field_formatter_settings_form($field, $instance, $view_mode, $form
if (strpos($display['type'], '_trimmed') !== FALSE) {
$element['trim_length'] = array(
'#title' => t('Trim length'),
'#type' => 'textfield',
'#type' => 'number',
'#size' => 10,
'#default_value' => $settings['trim_length'],
'#element_validate' => array('element_validate_integer_positive'),
'#min' => 1,
'#required' => TRUE,
);
}
......@@ -476,20 +476,20 @@ function text_field_widget_settings_form($field, $instance) {
if ($widget['type'] == 'text_textfield') {
$form['size'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Size of textfield'),
'#default_value' => $settings['size'],
'#required' => TRUE,
'#element_validate' => array('element_validate_integer_positive'),
'#min' => 1,
);
}
else {
$form['rows'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Rows'),
'#default_value' => $settings['rows'],
'#required' => TRUE,
'#element_validate' => array('element_validate_integer_positive'),
'#min' => 1,
);
}
......
......@@ -38,11 +38,11 @@
function hook_field_settings_form($field, $instance, $has_data) {
$settings = $field['settings'];
$form['max_length'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Maximum length'),
'#default_value' => $settings['max_length'],
'#required' => FALSE,
'#element_validate' => array('element_validate_integer_positive'),
'#min' => 1,
'#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'),
);
return $form;
......@@ -110,19 +110,19 @@ function hook_field_widget_settings_form($field, $instance) {
if ($widget['type'] == 'text_textfield') {
$form['size'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Size of textfield'),
'#default_value' => $settings['size'],
'#element_validate' => array('element_validate_integer_positive'),
'#min' => 1,
'#required' => TRUE,
);
}
else {
$form['rows'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Rows'),
'#default_value' => $settings['rows'],
'#element_validate' => array('element_validate_integer_positive'),
'#min' => 1,
'#required' => TRUE,
);
}
......@@ -157,10 +157,10 @@ function hook_field_formatter_settings_form($field, $instance, $view_mode, $form
if ($display['type'] == 'text_trimmed' || $display['type'] == 'text_summary_or_trimmed') {
$element['trim_length'] = array(
'#title' => t('Length'),
'#type' => 'textfield',
'#type' => 'number',
'#size' => 20,
'#default_value' => $settings['trim_length'],
'#element_validate' => array('element_validate_integer_positive'),
'#min' => 1,
'#required' => TRUE,
);
}
......
......@@ -383,15 +383,15 @@ function _poll_choice_form($key, $chid = NULL, $value = '', $votes = 0, $weight
);
$form['chvotes'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => $value !== '' ? t('Vote count for choice @label', array('@label' => $value)) : t('Vote count for new choice'),
'#title_display' => 'invisible',
'#default_value' => $votes,
'#size' => 5,
'#maxlength' => 7,
'#min' => 0,
'#parents' => array('choice', $key, 'chvotes'),
'#access' => user_access('administer nodes'),
'#element_validate' => array('element_validate_integer'),
);
$form['weight'] = array(
......@@ -441,9 +441,6 @@ function poll_validate($node, $form) {
if ($choice['chtext'] != '') {
$realchoices++;
}
if (isset($choice['chvotes']) && $choice['chvotes'] < 0) {
form_set_error("choice][$i][chvotes", t('Negative values are not allowed.'));
}
}
if ($realchoices < 2) {
......
......@@ -47,8 +47,8 @@ class PollWebTestCase extends DrupalWebTestCase {
$edit['choice[new:1][chvotes]'] = -1;
$edit['choice[new:0][chvotes]'] = $this->randomString(7);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('Negative values are not allowed.'));
$this->assertText(t('Vote count for new choice must be an integer.'));
$this->assertText(t('Vote count for new choice must be higher or equal to 0.'));
$this->assertText(t('Vote count for new choice must be a number.'));
// Repeat steps for initializing the state of the internal browser.
$this->drupalLogin($web_user);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment