Pull merge.
[yaffs-website] / web / core / modules / views / src / Plugin / views / filter / Equality.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\filter;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * Simple filter to handle equal to / not equal to filters
9  *
10  * @ingroup views_filter_handlers
11  *
12  * @ViewsFilter("equality")
13  */
14 class Equality extends FilterPluginBase {
15
16   // exposed filter options
17   protected $alwaysMultiple = TRUE;
18
19   /**
20    * Provide simple equality operator
21    */
22   public function operatorOptions() {
23     return [
24       '=' => $this->t('Is equal to'),
25       '!=' => $this->t('Is not equal to'),
26     ];
27   }
28
29   /**
30    * Provide a simple textfield for equality
31    */
32   protected function valueForm(&$form, FormStateInterface $form_state) {
33     $form['value'] = [
34       '#type' => 'textfield',
35       '#title' => $this->t('Value'),
36       '#size' => 30,
37       '#default_value' => $this->value,
38     ];
39
40     if ($exposed = $form_state->get('exposed')) {
41       $identifier = $this->options['expose']['identifier'];
42       $user_input = $form_state->getUserInput();
43       if (!isset($user_input[$identifier])) {
44         $user_input[$identifier] = $this->value;
45         $form_state->setUserInput($user_input);
46       }
47     }
48   }
49
50 }