You are here

public function Combine::validate in Drupal 10

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

Overrides FilterPluginBase::validate

File

core/modules/views/src/Plugin/views/filter/Combine.php, line 104

Class

Combine
Filter handler which allows to search on multiple fields.

Namespace

Drupal\views\Plugin\views\filter

Code

public function validate() {
  $errors = parent::validate();
  if ($this->displayHandler
    ->usesFields()) {
    $fields = $this->displayHandler
      ->getHandlers('field');
    foreach ($this->options['fields'] as $id) {
      if (!isset($fields[$id])) {

        // Combined field filter only works with fields that are in the field
        // settings.
        $errors[] = $this
          ->t('Field %field set in %filter is not set in display %display.', [
          '%field' => $id,
          '%filter' => $this
            ->adminLabel(),
          '%display' => $this->displayHandler->display['display_title'],
        ]);
        break;
      }
      elseif (!$fields[$id]
        ->clickSortable()) {

        // Combined field filter only works with simple fields. If the field
        // is not click sortable we can assume it is not a simple field.
        // @todo change this check to isComputed. See
        // https://www.drupal.org/node/2349465
        $errors[] = $this
          ->t('Field %field set in %filter is not usable for this filter type. Combined field filter only works for simple fields.', [
          '%field' => $fields[$id]
            ->adminLabel(),
          '%filter' => $this
            ->adminLabel(),
        ]);
      }
    }
  }
  else {
    $errors[] = $this
      ->t('%display: %filter can only be used on displays that use fields. Set the style or row format for that display to one using fields to use the combine field filter.', [
      '%display' => $this->displayHandler->display['display_title'],
      '%filter' => $this
        ->adminLabel(),
    ]);
  }
  return $errors;
}