text_field_validate
function text_field_validate
text_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors)
Implements hook_field_validate().
Possible error codes:
- 'text_value_max_length': The value exceeds the maximum length.
- 'text_summary_max_length': The summary exceeds the maximum length.
File
- modules/field/modules/text/text.module, line 118
- Defines simple text field types.
Code
function text_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { foreach ($items as $delta => $item) { // @todo Length is counted separately for summary and value, so the maximum // length can be exceeded very easily. foreach (array('value', 'summary') as $column) { if (!empty($item[$column])) { if (!empty($field['settings']['max_length']) && drupal_strlen($item[$column]) > $field['settings']['max_length']) { switch ($column) { case 'value': $message = t('%name: the text may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length'])); break; case 'summary': $message = t('%name: the summary may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length'])); break; } $errors[$field['field_name']][$langcode][$delta][] = array( 'error' => "text_{$column}_length", 'message' => $message, ); } } } } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!modules!text!text.module/function/text_field_validate/7.x