You are here

function calendar_plugin_style::validate in Calendar 7

Same name and namespace in other branches
  1. 6.2 includes/calendar_plugin_style.inc \calendar_plugin_style::validate()
  2. 7.2 includes/calendar_plugin_style.inc \calendar_plugin_style::validate()

Style validation.

Overrides views_plugin_style::validate

File

includes/calendar_plugin_style.inc, line 73
Views navigation style plugin for the Calendar module.

Class

calendar_plugin_style
Style plugin to create the calendar navigation and links.

Code

function validate() {
  $errors = parent::validate();
  if (empty($this->display->display_options['style_plugin'])) {
    return $errors;
  }
  $style = $this->display->display_options['style_plugin'];
  $arguments = $this->display->handler
    ->get_option('arguments');
  if (!in_array('date_argument', array_keys($arguments))) {
    if (empty($this->view->date_info->arg_missing)) {
      $errors[$style] = t("The @style style requires a Date argument.", array(
        '@style' => $style,
      ));
    }
    $this->view->date_info->arg_missing = TRUE;
  }
  elseif ($arguments['date_argument']['default_action'] != 'default' || $arguments['date_argument']['default_argument_type'] != 'date') {
    if (empty($this->view->date_info->arg_missing_default)) {
      $errors[] = calendar_errors('missing_argument_default');
    }
    $this->view->date_info->arg_missing_default = TRUE;
  }

  // Make sure date fields are not set up to 'Group multiple values'
  // in the calendar style.
  if ($style == 'calendar_style') {
    $view_fields = date_views_fields('node');
    $view_fields = $view_fields['name'];
    $fields = $this->display->handler
      ->get_option('fields');
    foreach ($fields as $column => $field) {
      $field_name = $field['table'] . "." . $field['field'];
      if (!empty($field['multiple']) && array_key_exists($field_name, $view_fields)) {
        $cck_fields = field_info_fields();
        $real_name = $view_fields[$field_name]['real_field_name'];
        if ($cck_fields[$real_name]['multiple'] && !empty($field['multiple']['group'])) {
          $errors[] = t("The date field '@field' used by the display '@display_title' cannot be set to 'Group multiple values'.", array(
            '@field' => $view_fields[$field_name]['label'],
            '@display_title' => $this->display->display_title,
          ));
        }
      }
    }
  }
  return $errors;
}