function options_field_validate

Implements hook_field_validate().

Possible error codes:

  • 'list_illegal_value': The value is not part of the list of allowed values.

File

drupal/core/modules/options/options.module, line 402
Defines selection, check box and radio button widgets for text and numeric fields.

Code

function options_field_validate(EntityInterface $entity = NULL, $field, $instance, $langcode, $items, &$errors) {
  $allowed_values = options_allowed_values($field, $instance, $entity);
  foreach ($items as $delta => $item) {
    if (!empty($item['value'])) {
      if (!empty($allowed_values) && !isset($allowed_values[$item['value']])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'list_illegal_value',
          'message' => t('%name: illegal value.', array(
            '%name' => $instance['label'],
          )),
        );
      }
    }
  }
}