You are here

function classy_paragraphs_field_validate in Classy paragraphs 7

Implements hook_field_validate().

File

includes/classy_paragraphs.fields.inc, line 39
Implements custom field: cp_list (CLASSY_PARAGRAPHS_FIELD_TYPE_LIST).

Code

function classy_paragraphs_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    if (!empty($item['value'])) {
      $selected = $item['value'];
      $possible_options = classy_paragraphs_get_options($field, $instance);

      // Validate the selected option.
      if (!isset($possible_options[$selected])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'cp_list_invalid',
          'message' => t('Selected option "%selected" is not allowed.', array(
            '%selected' => $selected,
          )),
        );
      }
    }
  }
}