Equality.php 1.18 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Plugin\views\filter\Equality.
6 7
 */

8
namespace Drupal\views\Plugin\views\filter;
9

10 11
use Drupal\Core\Form\FormStateInterface;

12 13 14 15
/**
 * Simple filter to handle equal to / not equal to filters
 *
 * @ingroup views_filter_handlers
16
 *
17
 * @ViewsFilter("equality")
18
 */
19
class Equality extends FilterPluginBase {
20

21
  // exposed filter options
22
  protected $alwaysMultiple = TRUE;
23 24 25 26

  /**
   * Provide simple equality operator
   */
27
  public function operatorOptions() {
28 29 30 31 32 33 34 35 36
    return array(
      '=' => t('Is equal to'),
      '!=' => t('Is not equal to'),
    );
  }

  /**
   * Provide a simple textfield for equality
   */
37
  protected function valueForm(&$form, FormStateInterface $form_state) {
38 39 40 41 42 43 44
    $form['value'] = array(
      '#type' => 'textfield',
      '#title' => t('Value'),
      '#size' => 30,
      '#default_value' => $this->value,
    );

45
    if ($exposed = $form_state->get('exposed')) {
46
      $identifier = $this->options['expose']['identifier'];
47 48 49 50
      $user_input = $form_state->getUserInput();
      if (!isset($user_input[$identifier])) {
        $user_input[$identifier] = $this->value;
        $form_state->setUserInput($user_input);
51 52 53
      }
    }
  }
54

55
}