function FilterPluginBase::validateExposeForm

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::validateExposeForm()
  2. 8.9.x core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::validateExposeForm()
  3. 11.x core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::validateExposeForm()

Validate the options form.

Parameters

array $form: Associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides HandlerBase::validateExposeForm

1 call to FilterPluginBase::validateExposeForm()
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 780

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

public function validateExposeForm($form, FormStateInterface $form_state) {
  $identifier = $form_state->getValue([
    'options',
    'expose',
    'identifier',
  ]);
  $this->validateIdentifier($identifier, $form_state, $form['expose']['identifier']);
  $limit_operators = $form_state->getValue([
    'options',
    'expose',
    'operator_limit_selection',
  ]);
  $operators_selected = $form_state->getValue([
    'options',
    'expose',
    'operator_list',
  ]);
  $selected_operator = $form_state->getValue([
    'options',
    'operator',
  ]);
  if ($limit_operators && !in_array($selected_operator, $operators_selected, TRUE)) {
    $form_state->setError($form['expose']['operator_list'], $this->t('You selected the "@operator" operator as the default value but is not included in the list of limited operators.', [
      '@operator' => $this->operatorOptions()[$selected_operator],
    ]));
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.