You are here

protected function FilterPluginBase::buildGroupValidate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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
1 method overrides FilterPluginBase::buildGroupValidate()
Date::buildGroupValidate in core/modules/views/src/Plugin/views/filter/Date.php
Validate the build group options form.

File

core/modules/views/src/Plugin/views/filter/FilterPluginBase.php, line 641
Contains \Drupal\views\Plugin\views\filter\FilterPluginBase.

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(array(
    'options',
    'group_info',
  ))) {
    $identifier = $form_state
      ->getValue(array(
      'options',
      'group_info',
      'identifier',
    ));
    if (empty($identifier)) {
      $form_state
        ->setError($form['group_info']['identifier'], $this
        ->t('The identifier is required if the filter is exposed.'));
    }
    elseif ($identifier == 'value') {
      $form_state
        ->setError($form['group_info']['identifier'], $this
        ->t('This identifier is not allowed.'));
    }
    if (!$this->view->display_handler
      ->isIdentifierUnique($form_state
      ->get('id'), $identifier)) {
      $form_state
        ->setError($form['group_info']['identifier'], $this
        ->t('This identifier is used by another handler.'));
    }
  }
  if ($group_items = $form_state
    ->getValue(array(
    'options',
    'group_info',
    'group_items',
  ))) {
    $operators = $this
      ->operators();
    foreach ($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_state
              ->setError($form['group_info']['group_items'][$id]['value'], $this
              ->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_state
              ->setError($form['group_info']['group_items'][$id]['title'], $this
              ->t('The title is required if value for this item is defined.'));
          }
        }
      }
    }
  }
}