function _calendar_views_validate in Calendar 5.2
Same name and namespace in other branches
- 5 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 246 - 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) {
$calendar_fields = array_keys(calendar_fields());
$fields = array();
// list (and table) modes require there to be at least 1 field active.
if (is_array($view['field'])) {
foreach ($view['field'] as $key => $value) {
if (is_numeric($key)) {
if (in_array($view['field'][$key]['field'], $calendar_fields)) {
$fields[] = $view['field'][$key]['field'];
}
}
}
}
if ($form['field'] && !$fields) {
form_error($form['field'], t('The Calendar View requires at least one date 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 requires 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());
// Include content_views handlers as well as newer date_views handlers
// so this will work until views are updated.
$handlers = array(
'content_views_field_handler_group',
'content_views_field_handler_first',
'content_views_field_handler_last',
'date_views_field_handler_group',
'date_views_field_handler_first',
'date_views_field_handler_last',
);
foreach ($view['field'] as $delta => $field) {
if (in_array($field['field'], $calendar_fields) && in_array($field['handler'], $handlers)) {
form_error($form['field'][$delta]['handler'], t('Calendar CCK Date fields must be set to \'Do not group multiple values\'.'));
}
}
}