3 namespace Drupal\views\Plugin\views\exposed_form;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\ViewsPluginInterface;
9 * @defgroup views_exposed_form_plugins Views exposed form plugins
11 * Plugins that handle validation, submission, and rendering of exposed forms.
13 * Exposed forms are used for filters, sorts, and pager settings that are
14 * exposed to site visitors. Exposed form plugins handle the rendering,
15 * validation, and submission of exposed forms, and may add additional form
18 * To define a Exposed Form Plugin in a module you need to:
20 * \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface.
21 * - Usually you will want to extend the
22 * \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase class.
23 * - Exposed form plugins are annotated with
24 * \Drupal\views\Annotation\ViewsExposedForm annotation. See the
25 * @link annotation Annotations topic @endlink for more information about
27 * - They must be in namespace directory Plugin\views\exposed_form.
31 * Interface for exposed filter form plugins.
33 * Exposed form plugins handle the rendering, validation, and submission
34 * of exposed forms, and may add additional form elements. These plugins can
35 * also alter the view query. See
36 * \Drupal\views\Plugin\views\exposed_form\InputRequired as an example of
39 * @see \Drupal\views\Annotation\ViewsExposedForm
40 * @see \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase
42 interface ExposedFormPluginInterface extends ViewsPluginInterface {
45 * Renders the exposed form.
47 * This method iterates over each handler configured to expose widgets
48 * to the end user and attach those widgets to the exposed form.
51 * (optional) TRUE if the exposed form is being rendered as part of a
52 * block; FALSE (default) if not.
55 * Form build array. This method returns an empty array if the form is
56 * being rendered as a block.
58 * @see \Drupal\views\ViewExecutable::build()
60 public function renderExposedForm($block = FALSE);
63 * Runs before the view is rendered.
65 * Implement if your exposed form needs to run code before the view is
68 * @param \Drupal\views\ResultRow[] $values
69 * An array of all ResultRow objects returned from the query.
71 * @see \Drupal\views\ViewExecutable::render()
73 public function preRender($values);
76 * Runs after the view has been rendered.
78 * Implement if your exposed form needs to run code after the view is
81 * @param string $output
82 * The rendered output of the view display.
84 * @see \Drupal\views\ViewExecutable::render()
86 public function postRender(&$output);
89 * Runs before the view has been executed.
91 * Implement if your exposed form needs to run code before query execution.
93 * @see \Drupal\views\Plugin\views\display\DisplayPluginBase::preExecute()
95 public function preExecute();
98 * Runs after the view has been executed.
100 * Implement if your exposed form needs to run code after query execution.
102 public function postExecute();
105 * Alters the exposed form.
107 * The exposed form is built by calling the renderExposedForm() method on
108 * this class, and then letting each exposed filter and sort handler add
109 * widgets to the form. After that is finished, this method is called to
110 * let the class alter the finished form.
113 * An associative array containing the structure of the form.
114 * @param \Drupal\Core\Form\FormStateInterface $form_state
115 * The current state of the form.
117 * @see \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface::renderExposedForm()
118 * @see \Drupal\views\Form\ViewsExposedForm::buildForm()
120 public function exposedFormAlter(&$form, FormStateInterface $form_state);
123 * Validates the exposed form submission.
126 * An associative array containing the structure of the form.
127 * @param \Drupal\Core\Form\FormStateInterface $form_state
128 * The current state of the form.
130 * @see \Drupal\views\Form\ViewsExposedForm::validateForm()
132 public function exposedFormValidate(&$form, FormStateInterface $form_state);
135 * Submits the exposed form.
138 * An associative array containing the structure of the form.
139 * @param \Drupal\Core\Form\FormStateInterface $form_state
140 * The current state of the form.
141 * @param array $exclude
142 * Array of keys that will not appear in $view->exposed_raw_input; for
143 * example, 'form_build_id'.
145 * @see \Drupal\views\Form\ViewsExposedForm::submitForm()
147 public function exposedFormSubmit(&$form, FormStateInterface $form_state, &$exclude);