You are here

function paragraphs_pack_field_validate in Paragraphs pack 7

Implements hook_field_validate().

File

includes/paragraphs_pack.fields.inc, line 30
Implements custom fields: PP_FIELD_TYPE_VIEW_MODE.

Code

function paragraphs_pack_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    if (!empty($item['value'])) {
      $view_mode = $item['value'];
      $possible_view_modes = paragraphs_pack_get_allowed_view_modes($instance);

      // Validate the view mode.
      if ($view_mode != PP_VALUE_DEFAULT && !isset($possible_view_modes[$view_mode])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'pp_view_mode_invalid',
          'message' => t('View mode key "%view_mode" doesn\'t exist.', array(
            '%view_mode' => $view_mode,
          )),
        );
      }
    }
  }
}