You are here

function rooms_availability_reference_field_validate in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Implements hook_field_validate().

File

modules/rooms_availability_reference/rooms_availability_reference.module, line 187
Defines a field type for referencing availability information

Code

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

  // Extract unit ids to check.
  $ids = array();

  // Check for non-numeric values.
  // First check non-numeric "nid's to avoid losing time with them.
  foreach ($items as $delta => $item) {
    if (is_array($item) && !empty($item['unit_id'])) {
      if (is_numeric($item['unit_id'])) {
        $ids[] = $item['unit_id'];
      }
      else {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'invalid_unit_id',
          'message' => t('%name: invalid input.', array(
            '%name' => $instance['label'],
          )),
        );
      }
    }
  }
}