3 namespace Drupal\fontyourface\Plugin\views\filter;
5 use Drupal\views\Plugin\views\filter\StringFilter;
6 use Drupal\Core\Form\FormStateInterface;
9 * Filter handler which allows to search based on font weight.
11 * @ingroup views_filter_handlers
13 * @ViewsFilter("fontyourface_font_weight")
15 class FontYourFaceWeightFilter extends StringFilter {
18 * Exposed filter options.
22 protected $alwaysMultiple = TRUE;
25 * Provide simple equality operator.
27 public function operators() {
30 'title' => $this->t('Is equal to'),
31 'short' => $this->t('='),
32 'method' => 'opEqual',
41 protected function valueForm(&$form, FormStateInterface $form_state) {
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'),
57 '#title' => $this->t('Font Weight'),
58 '#options' => $options,
59 '#default_value' => $this->value,
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);