You are here

public function EntityReferenceBehavior_Merci::validate in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Act on validating an entity reference field.

Overrides EntityReference_BehaviorHandler_Abstract::validate

See also

hook_field_validate()

File

merci_entityref_behavior/plugins/behavior/EntityReferenceBehavior_Merci.class.php, line 92
CTools plugin class for the taxonomy-index behavior.

Class

EntityReferenceBehavior_Merci
Extends an entityreference field to maintain its references to taxonomy terms in the {taxonomy_index} table.

Code

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

  // Check of conflicts.
  if (!$entity) {
    return;
  }
  $context = array(
    'quantity_field' => 'field_quantity',
    'date_field' => $field['settings']['handler_settings']['behaviors']['merci']['merci']['merci_date_field'],
    'item_field' => $field['field_name'],
  );
  $line_item_wrapper = entity_metadata_wrapper($entity_type, $entity);
  $controller = merci_get_controller($line_item_wrapper, 'non_inventory', $context);
  foreach ($controller
    ->getErrors() as $delta => $errors) {
    $msg = array();
    if (array_key_exists(MERCI_ERROR_TOO_MANY, $errors)) {
      $msg[] = $errors[MERCI_ERROR_TOO_MANY];
    }
    elseif (array_key_exists(MERCI_ERROR_CONFLICT, $errors)) {
      foreach ($errors[MERCI_ERROR_CONFLICT] as $date_start => $message) {
        $msg[] = $message;
      }
    }
    $errors[$field['field_name']][$langcode][$delta][] = array(
      'error' => 'merci',
      'message' => implode('<br>', $msg),
    );
  }
}