Equality.php

Same filename in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/Equality.php
  2. 8.9.x core/modules/views/src/Plugin/views/filter/Equality.php
  3. 10 core/modules/views/src/Plugin/views/filter/Equality.php

Namespace

Drupal\views\Plugin\views\filter

File

core/modules/views/src/Plugin/views/filter/Equality.php

View source
<?php

namespace Drupal\views\Plugin\views\filter;

use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Attribute\ViewsFilter;

/**
 * Simple filter to handle equal to / not equal to filters.
 *
 * @ingroup views_filter_handlers
 */
class Equality extends FilterPluginBase {
    
    /**
     * Exposed filter options.
     *
     * @var bool
     */
    protected $alwaysMultiple = TRUE;
    
    /**
     * Provide simple equality operator.
     */
    public function operatorOptions() {
        return [
            '=' => $this->t('Is equal to'),
            '!=' => $this->t('Is not equal to'),
        ];
    }
    
    /**
     * Provide a simple textfield for equality.
     */
    protected function valueForm(&$form, FormStateInterface $form_state) {
        $form['value'] = [
            '#type' => 'textfield',
            '#title' => $this->t('Value'),
            '#size' => 30,
            '#default_value' => $this->value,
        ];
        if ($form_state->get('exposed')) {
            $identifier = $this->options['expose']['identifier'];
            $user_input = $form_state->getUserInput();
            if (!isset($user_input[$identifier])) {
                $user_input[$identifier] = $this->value;
                $form_state->setUserInput($user_input);
            }
        }
    }

}

Classes

Title Deprecated Summary
Equality Simple filter to handle equal to / not equal to filters.

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