fe82e7cd7ca25cc1e43c397dd14dc3c69c86e226
[yaffs-website] / web / modules / contrib / fontyourface / src / Plugin / views / filter / FontYourFaceStyleFilter.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 styles.
10  *
11  * @ingroup views_filter_handlers
12  *
13  * @ViewsFilter("fontyourface_font_style")
14  */
15 class FontYourFaceStyleFilter 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       'normal' => $this->t('Normal'),
45       'italic' => $this->t('Italics'),
46     ];
47
48     $form['value'] = [
49       '#type' => 'select',
50       '#title' => $this->t('Font Style'),
51       '#options' => $options,
52       '#default_value' => $this->value,
53     ];
54
55     if ($exposed = $form_state->get('exposed')) {
56       $identifier = $this->options['expose']['identifier'];
57       $user_input = $form_state->getUserInput();
58       if (!isset($user_input[$identifier])) {
59         $user_input[$identifier] = $this->value;
60         $form_state->setUserInput($user_input);
61       }
62     }
63   }
64
65 }