You are here

function _calendar_views_validate in Calendar 5

Same name and namespace in other branches
  1. 5.2 calendar_admin.inc \_calendar_views_validate()

Validate a view.

1 call to _calendar_views_validate()
calendar_views_validate in ./calendar.module
Validate a view during Views administration.

File

./calendar_admin.inc, line 170
This file contains administrative functions used only when setting up the calendar and views_hooks() that are called infrequently and cached. No need to parse all this code the rest of the time.

Code

function _calendar_views_validate($type, $view, $form) {

  // list (and table) modes require there to be at least 1 field active.
  if (is_array($view['field'])) {
    $fields = array_filter(array_keys($view['field']), 'is_numeric');
  }
  if (!$fields) {
    form_error($form["{$type}-info"][$type . '_type'], t('The Calendar View requires at least one field.'));
  }
  if (isset($view['field']['count'])) {
    $defaultsort = false;
    for ($i = 0; $i < $view['field']['count']; $i++) {
      if ($view['field'][$i]['defaultsort']) {
        if ($defaultsort) {
          form_error($form['field'][$i]['defaultsort'], t('You can only set on Default Sort on one field.'));
          break;
        }
        $defaultsort = true;
      }
    }
  }

  // Make sure all arguments are set to 'Display all values'.
  $arg_types = array();
  $cal_args = calendar_args();
  foreach ($view['argument'] as $delta => $argument) {
    if (in_array($argument['type'], $cal_args)) {
      $view['argument'][$delta]['argdefault'] = 2;
      if ($argument['argdefault'] != 2) {
        form_error($form['argument'][$delta]['argdefault'], t('Calendar arguments must be set to \'Display All Values\'.'));
      }
      $arg_types[] = $argument['type'];
    }
  }

  // Must have Year, Month, and Day or Year and Week calendar arguments.
  if (!in_array('calendar_year', $arg_types) && (!in_array('calendar_month', $arg_types) && !in_array('calendar_day', $arg_types) || !in_array('calendar_week', $arg_types))) {
    form_error($form['argument'], t('The Calendar requres as arguments Calendar: Year, Calendar: Month, and Calendar: Day, or Calendar: Year and Calendar: Week'));
  }

  // CCK date fields cannot use grouped handler.
  $calendar_fields = array_keys(calendar_fields());
  foreach ($view['field'] as $delta => $field) {
    if (in_array($field['field'], $calendar_fields) && $field['handler'] == 'content_views_field_handler_group') {
      form_error($form['field'][$delta]['handler'], t('Calendar CCK Date fields must be set to \'Do not group multiple values\'.'));
    }
  }
}