CheckboxWidget.php 1.44 KB
Newer Older
borisson_'s avatar
borisson_ committed
1
2
3
4
5
6
7
8
9
10
11
<?php

namespace Drupal\facetapi\Plugin\facetapi\Widget;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\facetapi\Widget\WidgetInterface;

/**
 * @FacetApiWidget(
 *   id = "checkbox",
12
 *   label = @Translation("List of checkboxes"),
borisson_'s avatar
borisson_ committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 *   description = @Translation("A widget that shows checkboxes"),
 * )
 *
 * Class CheckboxWidget
 */
class CheckboxWidget implements WidgetInterface {

  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function execute() {
    // Execute all the things.
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    return ['#markup' => 'checkbox widget'];
  }

  /**
   * {@inheritdoc}
   */
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  public function buildConfigurationForm(array $form, FormStateInterface $form_state, $config) {
    $checkbox_options = [
      'before' => $this->t('Before'),
      'after' => $this->t('After'),
    ];

    $form['checkbox_placement'] = [
      '#type' => 'radios',
      '#title' => $this->t('Checkbox placement'),
      '#description' => $this->t('Choose where the checkboxes should be placed'),
      '#options' => $checkbox_options,
      '#required' => TRUE,
    ];
    if (!is_null($config)) {
      $widget_configs = $config->get('widget_configs');
      if (isset($widget_configs['checkbox_placement'])) {
        $form['checkbox_placement']['#default_value'] = $widget_configs['checkbox_placement'];
      }
    }

borisson_'s avatar
borisson_ committed
59
60
61
62
    return $form;
  }

}