You are here

function atom_reference_field_validate in Scald: Media Management made easy 7

Implements hook_field_validate().

File

modules/fields/atom_reference/atom_reference.module, line 110
Defines a new field type, allowing to directly reference Scald Atoms from a node.

Code

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

  // Ensure that the types of the referenced atoms match the one of those
  // that were defined in the field configuration.
  $types = atom_reference_field_referenceable_types($instance);
  foreach ($items as $delta => $item) {
    if (empty($item['sid'])) {
      continue;
    }
    $atom = scald_fetch($item['sid']);
    if (!isset($types[$atom->type]) || empty($types[$atom->type])) {
      $errors[$field['field_name']][$langcode][$delta][] = array(
        'error' => 'atom_reference_bad_type',
        'message' => t("Atom %title is of type %type, which can't be referenced in field %field", array(
          '%title' => $atom->title,
          '%type' => $atom->type,
          '%field' => $instance['label'],
        )),
      );
    }
  }
}