You are here

function date_field_settings_validate in Date 8

Same name and namespace in other branches
  1. 5.2 date/date_admin.inc \date_field_settings_validate()
  2. 6.2 date/date_admin.inc \date_field_settings_validate()
  3. 6 date/date_admin.inc \date_field_settings_validate()
  4. 7.3 date.field.inc \date_field_settings_validate()
  5. 7 date_admin.inc \date_field_settings_validate()
  6. 7.2 date.field.inc \date_field_settings_validate()

Form validation handler for _date_field_settings_form().

2 string references to 'date_field_settings_validate'
date_field_field_settings_form in date_field/date_field.module
Helper function for date_field_settings_form().
_date_field_settings_form in ./date_admin.inc
Helper function for date_field_settings_form().

File

./date_admin.inc, line 215
Date administration code.

Code

function date_field_settings_validate(&$form, &$form_state) {
  $field =& $form_state['values']['field'];
  if ($field['settings']['tz_handling'] == 'none') {
    form_set_value($form['timezone_db'], '', $form_state);
  }
  else {
    form_set_value($form['timezone_db'], date_get_timezone_db($field['settings']['tz_handling']), $form_state);
  }
  if ($field['settings']['tz_handling'] != 'none' && !in_array('hour', array_filter($field['settings']['granularity']))) {
    form_set_error('field[settings][tz_handling]', t('Dates without hours granularity must not use any timezone handling.'));
  }

  // Extract the correct 'todate' value out of the two end date checkboxes.
  if ($field['settings']['enddate_get']) {
    if ($field['settings']['enddate_required']) {
      $field['settings']['todate'] = 'required';
    }
    else {
      $field['settings']['todate'] = 'optional';
    }
  }
  else {
    $field['settings']['todate'] = '';
  }

  // Don't save the pseudo values created in the UI.
  unset($field['settings']['enddate_get'], $field['settings']['enddate_required']);
  if (!empty($field['settings']['cache_enabled'])) {
    if (!is_numeric($field['settings']['cache_count'])) {
      form_set_error('field[settings][cache_count]', t('The number of cache values must be a number.'));
    }
    elseif ($field['settings']['cache_count'] < 0) {
      form_set_error('field[settings][cache_count]', t('The number of cache values must be a number 0 or greater.'));
    }
  }
}