You are here

function date_field_validate in Date 8

Same name and namespace in other branches
  1. 7.3 date.field.inc \date_field_validate()
  2. 7 date.field.inc \date_field_validate()
  3. 7.2 date.field.inc \date_field_validate()

Implements hook_field_validate().

File

./date.field.inc, line 85
Field hooks to implement a date field.

Code

function date_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  $field_name = $field['field_name'];
  $flexible = 0;

  // @TODO Figure out what we need here now.
  return;

  // Don't try to validate if there were any errors before this point
  // since the element won't have been munged back into a date.
  if (!form_get_errors()) {
    foreach ($items as $delta => $item) {
      if (is_array($item) && isset($item['value'])) {
        $keys = date_available_values($field, $instance);
        $date1 = new DrupalDateTime($item['value'], $item['timezone'], date_type_format($field['type']));
        if (count($keys) == 1 || empty($item['value2']) && $item['value2'] !== 0) {
          $date2 = clone $date1;
        }
        else {
          $date2 = new DrupalDateTime($item['value2'], $item['timezone'], date_type_format($field['type']));
        }

        /*
                $valid1 = $date1->validGranularity($field['settings']['granularity'], $flexible);
                $valid2 = $date2->validGranularity($field['settings']['granularity'], $flexible);

                foreach ($keys as $key) {
                  if ($ == 'value' && $field['settings']['todate'] && !$valid1 && $valid2) {
                    $errors[$field['field_name']][$langcode][$delta][] = array(
                      'error' => 'value',
                      'message' => t("A 'Start date' date is required for field %field #%delta.", array('%delta' => $field['cardinality'] ? intval($delta + 1) : '', '%field' => $instance['label'])),
                    );
                  }
                  if ($key == 'value2' && $field['settings']['todate'] == 'required' && ($instance['required'] && $valid1 && !$valid2)) {
                    $errors[$field['field_name']][$langcode][$delta][] = array(
                      'error' => 'value2',
                      'message' => t("An 'End date' is required for field %field #%delta.", array('%delta' => $field['cardinality'] ? intval($delta + 1) : '', '%field' => $instance['label'])),
                    );
                  }
                }
        */
      }
    }
  }
}