You are here

public function views_aggregator_plugin_style_table::options_validate in Views Aggregator Plus 7

Overrides options_validate().

Overrides views_plugin_style::options_validate

File

views/views_aggregator_plugin_style_table.inc, line 224
views_aggregator_plugin_style_table.inc

Class

views_aggregator_plugin_style_table
Style plugin to render each item as a row in a table.

Code

public function options_validate(&$form, &$form_state) {
  parent::options_validate($form, $form_state);
  $allowed_tags = array(
    'b',
    'br',
    'em',
    'i',
    'p',
    'strong',
    'u',
  );
  $tag_msg = t('<strong>Parameter</strong> field contains an illegal character or illegal HTML tag. Allowed tags are: %tags', array(
    '%tags' => implode(', ', $allowed_tags),
  ));

  // Count the number of occurrences of the grouping and other aggregation
  // functions.
  $num_grouped = 0;
  $num_aggregation_functions = 0;
  foreach ($form_state['values']['style_options']['info'] as $field_name => $options) {
    if (!empty($options['has_aggr'])) {
      if (in_array('views_aggregator_group_and_compress', $options['aggr'])) {
        $num_grouped++;
      }
      elseif (!in_array('views_aggregator_row_filter', $options['aggr'])) {
        $num_aggregation_functions += count($options['aggr']);
      }
    }
    $filtered = filter_xss($options['aggr_par'], $allowed_tags);
    if ($options['aggr_par'] != $filtered) {
      form_error($form['info'][$field_name]['aggr_par'], $tag_msg);
    }
    $filtered = filter_xss($options['aggr_par_column'], $allowed_tags);
    if ($options['aggr_par_column'] != $filtered) {
      form_error($form['info'][$field_name]['aggr_par_column'], $tag_msg);
    }
  }

  // When we have no aggregation functions, we must have 0 or 1 grouping
  // function. When we have aggregation functions, there must be 1 grouping.
  $ok = $num_aggregation_functions == 0 ? $num_grouped <= 1 : $num_grouped == 1;
  if (!$ok) {
    $msg = t('When applying group aggregation functions, you must also select <em>"Group and compress"</em> on exactly one field.');
    foreach ($form_state['values']['style_options']['info'] as $field_name => $options) {
      form_error($form['info'][$field_name]['aggr'], $msg);
      $msg = '';
    }
  }
}