cb60ccb73cefe13dd4541707676cca43c61f76f5
[yaffs-website] / web / modules / contrib / fontyourface / src / Plugin / views / filter / FontYourFaceProviderFilter.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 providers.
10  *
11  * @ingroup views_filter_handlers
12  *
13  * @ViewsFilter("fontyourface_font_pid")
14  */
15 class FontYourFaceProviderFilter 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 = ['All' => '- Any -'];
43     foreach (\Drupal::moduleHandler()->getImplementations('fontyourface_api') as $module_name) {
44       $name = $module_name;
45       $module_info = \Drupal::moduleHandler()->invoke($module_name, 'fontyourface_api');
46       if ($module_info['name']) {
47         $name = $module_info['name'];
48       }
49       $options[$module_name] = $module_info['name'];
50     }
51
52     $form['value'] = [
53       '#type' => 'select',
54       '#title' => $this->t('Font Provider'),
55       '#options' => $options,
56       '#default_value' => $this->value,
57     ];
58
59     if ($exposed = $form_state->get('exposed')) {
60       $identifier = $this->options['expose']['identifier'];
61       $user_input = $form_state->getUserInput();
62       if (!isset($user_input[$identifier])) {
63         $user_input[$identifier] = $this->value;
64         $form_state->setUserInput($user_input);
65       }
66     }
67   }
68
69 }