2e956396194de334697d796efff708bf8c6a9ca1
[yaffs-website] / web / modules / contrib / fontyourface / src / Plugin / views / filter / FontYourFaceWeightFilter.php
1 <?php
2
3 namespace Drupal\fontyourface\Plugin\views\filter;
4
5 use Drupal\views\Plugin\views\filter\StringFilter;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Filter handler which allows to search based on font weight.
10  *
11  * @ingroup views_filter_handlers
12  *
13  * @ViewsFilter("fontyourface_font_weight")
14  */
15 class FontYourFaceWeightFilter extends StringFilter {
16
17   /**
18    * Exposed filter options.
19    *
20    * @var bool
21    */
22   protected $alwaysMultiple = TRUE;
23
24   /**
25    * Provide simple equality operator.
26    */
27   public function operators() {
28     return [
29       '=' => [
30         'title' => $this->t('Is equal to'),
31         'short' => $this->t('='),
32         'method' => 'opEqual',
33         'values' => 1,
34       ],
35     ];
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   protected function valueForm(&$form, FormStateInterface $form_state) {
42     $options = [
43       'All' => '- Any -',
44       '100' => $this->t('100'),
45       '200' => $this->t('200'),
46       '300' => $this->t('300'),
47       '400' => $this->t('400 (Normal)'),
48       '500' => $this->t('500'),
49       '600' => $this->t('600'),
50       '700' => $this->t('700 (Bold)'),
51       '800' => $this->t('800'),
52       '900' => $this->t('900'),
53     ];
54
55     $form['value'] = [
56       '#type' => 'select',
57       '#title' => $this->t('Font Weight'),
58       '#options' => $options,
59       '#default_value' => $this->value,
60     ];
61
62     if ($exposed = $form_state->get('exposed')) {
63       $identifier = $this->options['expose']['identifier'];
64       $user_input = $form_state->getUserInput();
65       if (!isset($user_input[$identifier])) {
66         $user_input[$identifier] = $this->value;
67         $form_state->setUserInput($user_input);
68       }
69     }
70   }
71
72 }