You are here

protected function FilterPluginBase::buildGroupValidate in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::buildGroupValidate()
  2. 10 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::buildGroupValidate()

Validate the build group options form.

1 call to FilterPluginBase::buildGroupValidate()
FilterPluginBase::validateOptionsForm in core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Simple validate handler

File

core/modules/views/src/Plugin/views/filter/FilterPluginBase.php, line 712

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function buildGroupValidate($form, FormStateInterface $form_state) {
  if (!$form_state
    ->isValueEmpty([
    'options',
    'group_info',
  ])) {
    $identifier = $form_state
      ->getValue([
      'options',
      'group_info',
      'identifier',
    ]);
    $this
      ->validateIdentifier($identifier, $form_state, $form['group_info']['identifier']);
  }
  if ($group_items = $form_state
    ->getValue([
    'options',
    'group_info',
    'group_items',
  ])) {
    foreach ($group_items as $id => $group) {
      if (empty($group['remove'])) {
        $has_valid_value = $this
          ->hasValidGroupedValue($group);
        if ($has_valid_value && $group['title'] == '') {
          $operators = $this
            ->operators();
          if ($operators[$group['operator']]['values'] == 0) {
            $form_state
              ->setError($form['group_info']['group_items'][$id]['title'], $this
              ->t('A label is required for the specified operator.'));
          }
          else {
            $form_state
              ->setError($form['group_info']['group_items'][$id]['title'], $this
              ->t('A label is required if the value for this item is defined.'));
          }
        }
        if (!$has_valid_value && $group['title'] != '') {
          $form_state
            ->setError($form['group_info']['group_items'][$id]['value'], $this
            ->t('A value is required if the label for this item is defined.'));
        }
      }
    }
  }
}