summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries Buytaert2011-08-01 01:54:41 (GMT)
committerDries Buytaert2011-08-01 01:54:41 (GMT)
commite05b585786c70cc516688efca4ce5c6075eb179d (patch)
tree39bdb661b917637cf4c5f953aada17ce2fc3c4fa
parent71d16d907d6950125c306a95f0c2daadd1714bcd (diff)
- Patch #1174444 by Boobaa, xjm, Dave Reid: Make the _element_validate_()* functions in field.module available for all contrib modules to use.
-rw-r--r--includes/form.inc30
-rw-r--r--modules/field/field.module30
-rw-r--r--modules/field/modules/number/number.module4
-rw-r--r--modules/field/modules/text/text.module8
-rw-r--r--modules/field_ui/field_ui.api.php8
5 files changed, 40 insertions, 40 deletions
diff --git a/includes/form.inc b/includes/form.inc
index 5dff07d4..c4f6f35 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -4004,6 +4004,36 @@ function _form_set_class(&$element, $class = array()) {
}
/**
+ * Helper form element validator: integer.
+ */
+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'])));
+ }
+}
+
+/**
+ * Helper form element validator: integer > 0.
+ */
+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'])));
+ }
+}
+
+/**
+ * Helper form element validator: number.
+ */
+function element_validate_number($element, &$form_state) {
+ $value = $element['#value'];
+ if ($value != '' && !is_numeric($value)) {
+ form_error($element, t('%name must be a number.', array('%name' => $element['#title'])));
+ }
+}
+
+/**
* @} End of "defgroup form_api".
*/
diff --git a/modules/field/field.module b/modules/field/field.module
index af9e8c8..6432ce0 100644
--- a/modules/field/field.module
+++ b/modules/field/field.module
@@ -1174,33 +1174,3 @@ function theme_field($variables) {
return $output;
}
-
-/**
- * Helper form element validator: integer.
- */
-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'])));
- }
-}
-
-/**
- * Helper form element validator: integer > 0.
- */
-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'])));
- }
-}
-
-/**
- * Helper form element validator: number.
- */
-function _element_validate_number($element, &$form_state) {
- $value = $element['#value'];
- if ($value != '' && !is_numeric($value)) {
- form_error($element, t('%name must be a number.', array('%name' => $element['#title'])));
- }
-}
diff --git a/modules/field/modules/number/number.module b/modules/field/modules/number/number.module
index 3c8132c..fd53673 100644
--- a/modules/field/modules/number/number.module
+++ b/modules/field/modules/number/number.module
@@ -98,14 +98,14 @@ function number_field_instance_settings_form($field, $instance) {
'#title' => t('Minimum'),
'#default_value' => $settings['min'],
'#description' => t('The minimum value that should be allowed in this field. Leave blank for no minimum.'),
- '#element_validate' => array('_element_validate_number'),
+ '#element_validate' => array('element_validate_number'),
);
$form['max'] = array(
'#type' => 'textfield',
'#title' => t('Maximum'),
'#default_value' => $settings['max'],
'#description' => t('The maximum value that should be allowed in this field. Leave blank for no maximum.'),
- '#element_validate' => array('_element_validate_number'),
+ '#element_validate' => array('element_validate_number'),
);
$form['prefix'] = array(
'#type' => 'textfield',
diff --git a/modules/field/modules/text/text.module b/modules/field/modules/text/text.module
index 89c605c..d73814f 100644
--- a/modules/field/modules/text/text.module
+++ b/modules/field/modules/text/text.module
@@ -71,7 +71,7 @@ function text_field_settings_form($field, $instance, $has_data) {
'#default_value' => $settings['max_length'],
'#required' => TRUE,
'#description' => t('The maximum length of the field in characters.'),
- '#element_validate' => array('_element_validate_integer_positive'),
+ '#element_validate' => array('element_validate_integer_positive'),
// @todo: If $has_data, add a validate handler that only allows
// max_length to increase.
'#disabled' => $has_data,
@@ -227,7 +227,7 @@ function text_field_formatter_settings_form($field, $instance, $view_mode, $form
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['trim_length'],
- '#element_validate' => array('_element_validate_integer_positive'),
+ '#element_validate' => array('element_validate_integer_positive'),
'#required' => TRUE,
);
}
@@ -480,7 +480,7 @@ function text_field_widget_settings_form($field, $instance) {
'#title' => t('Size of textfield'),
'#default_value' => $settings['size'],
'#required' => TRUE,
- '#element_validate' => array('_element_validate_integer_positive'),
+ '#element_validate' => array('element_validate_integer_positive'),
);
}
else {
@@ -489,7 +489,7 @@ function text_field_widget_settings_form($field, $instance) {
'#title' => t('Rows'),
'#default_value' => $settings['rows'],
'#required' => TRUE,
- '#element_validate' => array('_element_validate_integer_positive'),
+ '#element_validate' => array('element_validate_integer_positive'),
);
}
diff --git a/modules/field_ui/field_ui.api.php b/modules/field_ui/field_ui.api.php
index e07a937..b644652 100644
--- a/modules/field_ui/field_ui.api.php
+++ b/modules/field_ui/field_ui.api.php
@@ -42,7 +42,7 @@ function hook_field_settings_form($field, $instance, $has_data) {
'#title' => t('Maximum length'),
'#default_value' => $settings['max_length'],
'#required' => FALSE,
- '#element_validate' => array('_element_validate_integer_positive'),
+ '#element_validate' => array('element_validate_integer_positive'),
'#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'),
);
return $form;
@@ -113,7 +113,7 @@ function hook_field_widget_settings_form($field, $instance) {
'#type' => 'textfield',
'#title' => t('Size of textfield'),
'#default_value' => $settings['size'],
- '#element_validate' => array('_element_validate_integer_positive'),
+ '#element_validate' => array('element_validate_integer_positive'),
'#required' => TRUE,
);
}
@@ -122,7 +122,7 @@ function hook_field_widget_settings_form($field, $instance) {
'#type' => 'textfield',
'#title' => t('Rows'),
'#default_value' => $settings['rows'],
- '#element_validate' => array('_element_validate_integer_positive'),
+ '#element_validate' => array('element_validate_integer_positive'),
'#required' => TRUE,
);
}
@@ -160,7 +160,7 @@ function hook_field_formatter_settings_form($field, $instance, $view_mode, $form
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $settings['trim_length'],
- '#element_validate' => array('_element_validate_integer_positive'),
+ '#element_validate' => array('element_validate_integer_positive'),
'#required' => TRUE,
);
}