You are here

public function date_views_filter_handler_simple::input_validate in Date 7.3

Same name and namespace in other branches
  1. 7.2 date_views/includes/date_views_filter_handler_simple.inc \date_views_filter_handler_simple::input_validate()

Return form state input array appropriate to missing, valid, invalid input.

@todo Document this more thoroughly.

1 call to date_views_filter_handler_simple::input_validate()
date_views_filter_handler_simple::date_parts_form in date_views/includes/date_views_filter_handler_simple.inc
A form element to select date part values.

File

date_views/includes/date_views_filter_handler_simple.inc, line 531
A standard Views filter for a single date field.

Class

date_views_filter_handler_simple
A standard Views filter for a single date field.

Code

public function input_validate($element, $input) {
  if (!$input) {

    // No input value (e.g. initial form load), set value to NULL so Form API
    // calls the element value_callback routine with FALSE to set the '#value'
    // property from the '#default_value' property.
    // See _form_builder_handle_input_element().
    if ($element['#type'] != 'date_select') {
      return array(
        'date' => NULL,
      );
    }
    $granularity = date_format_order($element['#date_format']);
    if ($key = array_search('timezone', $granularity)) {
      unset($granularity[$key]);
    }
    return array_fill_keys($granularity, NULL);
  }

  // Include element defaults to avoid notices in the xxx_input_date routines.
  // Copied from form_builder() in form.inc.
  if (isset($element['#type']) && empty($element['#defaults_loaded']) && ($info = element_info($element['#type']))) {

    // Overlay $info onto $element, retaining preexisting keys in $element.
    $element += $info;
    $element['#defaults_loaded'] = TRUE;
  }
  $date = NULL;
  $function = "{$element['#type']}_input_date";
  if (($date = $function($element, $input)) && date_is_date($date)) {

    // The input is valid including being in the expected format.
    return $input;
  }
  if (is_object($date)) {

    // Input may not meet the granularity and format but is recognizable.
    return $input;
  }

  // Input is bogus, return empty array in granularity format.
  if ($element['#type'] != 'date_select') {
    return array(
      'date' => '',
    );
  }
  $granularity = date_format_order($element['#date_format']);
  if ($key = array_search('timezone', $granularity)) {
    unset($granularity[$key]);
  }
  return array_fill_keys($granularity, '');
}