You are here

function date_restrictions_element_validate in Date Restrictions 7

Validate callback for date form elements with #restrictions.

4 string references to 'date_restrictions_element_validate'
date_restrictions_allowed_values_module_implements_alter in modules/allowed_values/date_restrictions_allowed_values.module
Implements hook_module_implements_alter().
date_restrictions_date_popup_process_alter in ./date_restrictions.module
Implements hook_date_popup_process_alter().
date_restrictions_date_select_process_alter in ./date_restrictions.module
Implements hook_date_select_process_alter().
date_restrictions_date_text_process_alter in ./date_restrictions.module
Implements hook_date_text_process_alter().

File

./date_restrictions.module, line 167

Code

function date_restrictions_element_validate($element, &$form_state, $form) {
  if (form_get_error($element) || user_access('bypass date restrictions on edit')) {
    return;
  }

  // Convert input date to a proper date object.
  // This is a crude anticipation to the task performed later in
  // date_combo_validate().
  // No timezone conversion is done here.
  // @todo a way to fix this is doing validation on date_combo element,
  // instead of date elements. In this case we need also to check form
  // elements used outside of date_combo.
  $input = drupal_array_get_nested_value($form_state['input'], $element['#parents']);
  $function = $element['#type'] . '_input_date';
  $date = $function($element, $input);
  if ($date) {
    $hook = 'date_restrictions_element_validate';
    foreach (module_implements($hook) as $module) {
      $function = $module . '_' . $hook;
      $function($date, $element, $form_state, $form);

      // Don't try further validations since Drupal will
      // ignore error messages after the first one.
      // See @form_error().
      if (form_get_error($element)) {
        return;
      }
    }
  }
}