FilterTest.php

Same filename in this branch
  1. 9 core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php
  2. 9 core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FilterTest.php
  3. 9 core/modules/views/tests/src/Functional/Plugin/FilterTest.php
Same filename in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php
  2. 8.9.x core/modules/views/tests/src/Functional/Plugin/FilterTest.php
  3. 8.9.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/filter/FilterTest.php
  4. 10 core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php
  5. 10 core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FilterTest.php
  6. 10 core/modules/views/tests/src/Functional/Plugin/FilterTest.php
  7. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/filter/FilterTest.php
  8. 11.x core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php
  9. 11.x core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FilterTest.php
  10. 11.x core/modules/views/tests/src/Functional/Plugin/FilterTest.php
  11. 11.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/filter/FilterTest.php

Namespace

Drupal\views_test_data\Plugin\views\filter

File

core/modules/views/tests/modules/views_test_data/src/Plugin/views/filter/FilterTest.php

View source
<?php

namespace Drupal\views_test_data\Plugin\views\filter;

use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase;

/**
 * @ViewsFilter("test_filter")
 */
class FilterTest extends FilterPluginBase {
    
    /**
     * Overrides Drupal\views\Plugin\views\row\RowPluginBase::defineOptions().
     *
     * @return array
     */
    protected function defineOptions() {
        $options = parent::defineOptions();
        $options['test_enable'] = [
            'default' => TRUE,
        ];
        return $options;
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildOptionsForm(&$form, FormStateInterface $form_state) {
        parent::buildOptionsForm($form, $form_state);
        $form['test_enable'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Controls whether the filter plugin should be active'),
            '#default_value' => $this->options['test_enable'],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function query() {
        // Call the parent if this option is enabled.
        if ($this->options['test_enable']) {
            parent::query();
        }
    }

}

Classes

Title Deprecated Summary
FilterTest Plugin annotation @ViewsFilter("test_filter");

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.