3 namespace Drupal\views_test_data\Plugin\views\filter;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\filter\FilterPluginBase;
9 * @ViewsFilter("test_filter")
11 class FilterTest extends FilterPluginBase {
14 * Overrides Drupal\views\Plugin\views\row\RowPluginBase::defineOptions().
18 protected function defineOptions() {
19 $options = parent::defineOptions();
21 $options['test_enable'] = ['default' => TRUE];
26 * Overrides Drupal\views\Plugin\views\row\RowPluginBase::buildOptionsForm().
30 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
31 parent::buildOptionsForm($form, $form_state);
33 $form['test_enable'] = [
34 '#type' => 'checkbox',
35 '#title' => $this->t('Controls whether the filter plugin should be active'),
36 '#default_value' => $this->options['test_enable'],
43 public function query() {
44 // Call the parent if this option is enabled.
45 if ($this->options['test_enable']) {