diff --git a/core/modules/views/src/Annotation/ViewsExposedForm.php b/core/modules/views/src/Annotation/ViewsExposedForm.php index 0fa318e..062ab41 100644 --- a/core/modules/views/src/Annotation/ViewsExposedForm.php +++ b/core/modules/views/src/Annotation/ViewsExposedForm.php @@ -10,6 +10,7 @@ /** * Defines a Plugin annotation object for views exposed form plugins. * + * @see \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface * @see \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase * * @ingroup views_exposed_form_plugins diff --git a/core/modules/views/src/Form/ViewsExposedForm.php b/core/modules/views/src/Form/ViewsExposedForm.php index e2b91a5..fb23655 100644 --- a/core/modules/views/src/Form/ViewsExposedForm.php +++ b/core/modules/views/src/Form/ViewsExposedForm.php @@ -119,7 +119,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['#theme'] = $view->buildThemeFunctions('views_exposed_form'); $form['#id'] = Html::cleanCssIdentifier('views_exposed_form-' . $view->storage->id() . '-' . $display['id']); - /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */ + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form_plugin */ $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormAlter($form, $form_state); @@ -142,7 +142,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $handlers[$key]->validateExposed($form, $form_state); } } - /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */ + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form_plugin */ $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormValidate($form, $form_state); } @@ -164,7 +164,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $view->exposed_raw_input = []; $exclude = array('submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset'); - /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */ + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form_plugin */ $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormSubmit($form, $form_state, $exclude); diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 2348408..b0f6688 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -1344,6 +1344,7 @@ public function optionsSummary(&$categories, &$options) { ); } + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form_plugin */ $exposed_form_plugin = $this->getPlugin('exposed_form'); if (!$exposed_form_plugin) { // Default to the no cache control plugin. @@ -2255,6 +2256,7 @@ public function preExecute() { } $this->view->initHandlers(); if ($this->usesExposed()) { + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */ $exposed_form = $this->getPlugin('exposed_form'); $exposed_form->preExecute(); } @@ -2551,6 +2553,7 @@ public function viewExposedFormBlocks() { $this->view->initHandlers(); if ($this->usesExposed() && $this->getOption('exposed_block')) { + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */ $exposed_form = $this->getPlugin('exposed_form'); return $exposed_form->renderExposedForm(TRUE); } diff --git a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php index 33267b2..9b99b05 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -15,31 +15,20 @@ use Drupal\views\Plugin\views\PluginBase; /** - * @defgroup views_exposed_form_plugins Views exposed form plugins - * @{ - * Plugins that handle validation, submission, and rendering of exposed forms. - * - * Exposed forms are used for filters, sorts, and pager settings that are - * exposed to site visitors. Exposed form plugins handle the rendering, - * validation, and submission of exposed forms, and may add additional form - * elements. - * - * Exposed form plugins extend - * \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase. They must be - * annotated with \Drupal\views\Annotation\ViewsExposedForm annotation, - * and they must be in namespace directory Plugin\views\exposed_form. - */ - -/** * Base class for Views exposed filter form plugins. + * + * @ingroup views_exposed_form_plugins */ -abstract class ExposedFormPluginBase extends PluginBase implements CacheableDependencyInterface { +abstract class ExposedFormPluginBase extends PluginBase implements CacheableDependencyInterface, ExposedFormPluginInterface { /** * {@inheritdoc} */ protected $usesOptions = TRUE; + /** + * {@inheritdoc} + */ protected function defineOptions() { $options = parent::defineOptions(); $options['submit_button'] = array('default' => $this->t('Apply')); @@ -52,6 +41,9 @@ protected function defineOptions() { return $options; } + /** + * {@inheritdoc} + */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $form['submit_button'] = array( @@ -120,11 +112,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { } /** - * Render the exposed filter form. - * - * This actually does more than that; because it's using FAPI, the form will - * also assign data to the appropriate handlers for use in building the - * query. + * {@inheritdoc} */ public function renderExposedForm($block = FALSE) { // Deal with any exposed filters we may have, before building. @@ -159,6 +147,9 @@ public function renderExposedForm($block = FALSE) { } } + /** + * {@inheritdoc} + */ public function query() { $view = $this->view; $exposed_data = isset($view->exposed_data) ? $view->exposed_data : array(); @@ -184,21 +175,28 @@ public function query() { } } + /** + * {@inheritdoc} + */ public function preRender($values) { } + /** + * {@inheritdoc} + */ public function postRender(&$output) { } + /** + * {@inheritdoc} + */ public function preExecute() { } + /** + * {@inheritdoc} + */ public function postExecute() { } /** - * Alters the view exposed form. - * - * @param $form - * The form build array. Passed by reference. - * @param $form_state - * The form state. Passed by reference. + * {@inheritdoc} */ public function exposedFormAlter(&$form, FormStateInterface $form_state) { if (!empty($this->options['submit_button'])) { @@ -278,6 +276,9 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) { } } + /** + * {@inheritdoc} + */ public function exposedFormValidate(&$form, FormStateInterface $form_state) { if ($pager_plugin = $form_state->get('pager_plugin')) { $pager_plugin->exposedFormValidate($form, $form_state); @@ -285,15 +286,7 @@ public function exposedFormValidate(&$form, FormStateInterface $form_state) { } /** - * This function is executed when exposed form is submitted. - * - * @param $form - * Nested array of form elements that comprise the form. - * @param $form_state - * The current state of the form. - * @param $exclude - * Nested array of keys to exclude of insert into - * $view->exposed_raw_input + * {@inheritdoc} */ public function exposedFormSubmit(&$form, FormStateInterface $form_state, &$exclude) { if (!$form_state->isValueEmpty('op') && $form_state->getValue('op') == $this->options['reset_button_label']) { @@ -305,6 +298,17 @@ public function exposedFormSubmit(&$form, FormStateInterface $form_state, &$excl } } + /** + * Resets all the states of the exposed form. + * + * This method is called when the "Reset" button is triggered and clears + * user inputs, stored session, and the form state. + * + * @param array $form + * An associative array containing the structure of the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + */ public function resetForm(&$form, FormStateInterface $form_state) { // _SESSION is not defined for users who are not logged in. @@ -378,7 +382,3 @@ public function getCacheTags() { } } - -/** - * @} - */ diff --git a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginInterface.php b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginInterface.php new file mode 100644 index 0000000..de15ace --- /dev/null +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginInterface.php @@ -0,0 +1,156 @@ +exposed_raw_input; For + * example, 'form_build_id'. + * + * @see \Drupal\views\Form\ViewsExposedForm::submitForm() + */ + public function exposedFormSubmit(&$form, FormStateInterface $form_state, &$exclude); + +} + +/** + * @} + */ diff --git a/core/modules/views/src/Tests/Plugin/DisplayKernelTest.php b/core/modules/views/src/Tests/Plugin/DisplayKernelTest.php index e07a536..eba1883 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayKernelTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayKernelTest.php @@ -10,7 +10,7 @@ use Drupal\views\Tests\ViewKernelTestBase; use Drupal\views\Plugin\views\style\StylePluginBase; use Drupal\views\Plugin\views\access\AccessPluginBase; -use Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase; +use Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface; use Drupal\views\Plugin\views\pager\PagerPluginBase; use Drupal\views\Plugin\views\query\QueryPluginBase; use Drupal\views\Plugin\views\cache\CachePluginBase; @@ -100,7 +100,7 @@ public function testGetPlugin() { $this->assertTrue($display_handler->getPlugin('access') instanceof AccessPluginBase, 'An access plugin instance was returned.'); $this->assertTrue($display_handler->getPlugin('cache') instanceof CachePluginBase, 'A cache plugin instance was returned.'); - $this->assertTrue($display_handler->getPlugin('exposed_form') instanceof ExposedFormPluginBase, 'An exposed_form plugin instance was returned.'); + $this->assertTrue($display_handler->getPlugin('exposed_form') instanceof ExposedFormPluginInterface, 'An exposed_form plugin instance was returned.'); $this->assertTrue($display_handler->getPlugin('pager') instanceof PagerPluginBase, 'A pager plugin instance was returned.'); $this->assertTrue($display_handler->getPlugin('query') instanceof QueryPluginBase, 'A query plugin instance was returned.'); $this->assertTrue($display_handler->getPlugin('row') instanceof RowPluginBase, 'A row plugin instance was returned.'); diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index 4ad44fe..b9f5c27 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -1197,6 +1197,7 @@ public function build($display_id = NULL) { $this->_preQuery(); if ($this->display_handler->usesExposed()) { + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */ $exposed_form = $this->display_handler->getPlugin('exposed_form'); $this->exposed_widgets = $exposed_form->renderExposedForm(); if (FormState::hasAnyErrors() || !empty($this->build_info['abort'])) { @@ -1424,6 +1425,7 @@ public function render($display_id = NULL) { return; } + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */ $exposed_form = $this->display_handler->getPlugin('exposed_form'); $exposed_form->preRender($this->result);