1 date_views_filter_handler_simple.inc date_views_filter_handler_simple::value_validate($form, &$form_state)

Value validation.

TODO add in more validation.

We are setting an extra option using a value form because it makes more sense to set it there. That's not the normal method, so we have to manually transfer the selected value back to the option.

Overrides views_handler_filter::value_validate

File

core/modules/date/views/date_views_filter_handler_simple.inc, line 461
A standard Views filter for a single date field, using Date API form selectors and sql handling.

Class

date_views_filter_handler_simple
@file A standard Views filter for a single date field, using Date API form selectors and sql handling.

Code

function value_validate($form, &$form_state) {

  $options = &$form_state['values']['options'];

  if ($options['operator'] == 'between' || $options['operator'] == 'not between') {
    if ($options['value']['min_group']['min_choose_input_type'] == 'relative') {
      if (empty($options['value']['min_group']['default_date'])) {
        form_set_error('options][value][min_group][default_date', t('Relative start date not specified.'));
      }
      else {
        $this->options['default_date'] = $options['value']['min_group']['default_date'];
        // NULL out the value field, user wanted the relative value to take hold.
        $options['value']['min_group']['min'] = NULL;
      }
    }
    // If an absolute date was used, be sure to wipe the relative date.
    else {
      $this->options['default_date'] = '';
    }
    if ($options['value']['max_group']['max_choose_input_type'] == 'relative') {
      if (empty($options['value']['max_group']['default_to_date'])) {
        form_set_error('options][value][max_group][default_to_date', t('Relative end date not specified.'));
      }
      else {
        $this->options['default_to_date'] = $options['value']['max_group']['default_to_date'];
        // NULL out the value field, user wanted the relative value to take hold.
        $options['value']['max_group']['max'] = NULL;
      }
    }
    // If an absolute date was used, be sure to wipe the relative date.
    else {
      $this->options['default_to_date'] = '';
    }
  }
  elseif (in_array($options['operator'], array('<', '<=', '=', '!=', '>=', '>'))) {
    if ($options['value']['value_group']['value_choose_input_type'] == 'relative') {
      if (empty($options['value']['value_group']['default_date'])) {
        form_set_error('options][value][value_group][default_date', t('Relative date not specified.'));
      }
      else {
        $this->options['default_date'] = $options['value']['value_group']['default_date'];
        // NULL out the value field, user wanted the relative value to take hold.
        $options['value']['value_group']['value'] = NULL;
      }
    }
    // If an absolute date was used, be sure to wipe the relative date.
    else {
      $this->options['default_date'] = '';
    }
  }
  // Flatten the form structure for views, so the values can be saved.
  foreach (array('value', 'min', 'max') as $key) {
    $options['value'][$key] = $options['value'][$key . '_group'][$key];
  }
}