You are here

function cvm_field_field_validate in Contextual View Modes 7

Implements hook_field_validate().

File

modules/cvm_field/cvm_field.module, line 32

Code

function cvm_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {

  // For storing the context keys. Con't have more then one use of the context.
  $found = array();
  foreach ($items as $delta => $item) {
    if (!empty($item['context']) && $item['context'] !== "none") {
      if (in_array($item['context'], $found)) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'cvm_field_invalid',
          'message' => t("Contextual View Mode Error: %itm context already in use!", array(
            "%itm" => $item['context'],
          )),
        );
      }
      $found[] = $item['context'];
    }
  }
}