protected function FilterPluginBase::buildGroupValidate

Validate the build group options form.

1 call to FilterPluginBase::buildGroupValidate()
FilterPluginBase::validateOptionsForm in drupal/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php
Simple validate handler
1 method overrides FilterPluginBase::buildGroupValidate()
Date::buildGroupValidate in drupal/core/modules/views/lib/Drupal/views/Plugin/views/filter/Date.php
Validate the build group options form.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php, line 622
Definition of Drupal\views\Plugin\views\filter\FilterPluginBase.

Class

FilterPluginBase
Base class for filters.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function buildGroupValidate($form, &$form_state) {
  if (!empty($form_state['values']['options']['group_info'])) {
    if (empty($form_state['values']['options']['group_info']['identifier'])) {
      form_error($form['group_info']['identifier'], t('The identifier is required if the filter is exposed.'));
    }
    if (!empty($form_state['values']['options']['group_info']['identifier']) && $form_state['values']['options']['group_info']['identifier'] == 'value') {
      form_error($form['group_info']['identifier'], t('This identifier is not allowed.'));
    }
    if (!$this->view->display_handler
      ->isIdentifierUnique($form_state['id'], $form_state['values']['options']['group_info']['identifier'])) {
      form_error($form['group_info']['identifier'], t('This identifier is used by another handler.'));
    }
  }
  if (!empty($form_state['values']['options']['group_info']['group_items'])) {
    $operators = $this
      ->operators();
    foreach ($form_state['values']['options']['group_info']['group_items'] as $id => $group) {
      if (empty($group['remove'])) {

        // Check if the title is defined but value wasn't defined.
        if (!empty($group['title']) && $operators[$group['operator']]['values'] > 0) {
          if (!is_array($group['value']) && trim($group['value']) == "" || is_array($group['value']) && count(array_filter($group['value'], 'static::arrayFilterZero')) == 0) {
            form_error($form['group_info']['group_items'][$id]['value'], t('The value is required if title for this item is defined.'));
          }
        }

        // Check if the value is defined but title wasn't defined.
        if (!is_array($group['value']) && trim($group['value']) != "" || is_array($group['value']) && count(array_filter($group['value'], 'static::arrayFilterZero')) > 0) {
          if (empty($group['title'])) {
            form_error($form['group_info']['group_items'][$id]['title'], t('The title is required if value for this item is defined.'));
          }
        }
      }
    }
  }
}