Problem/Motivation
Exposed form is rendered in cases, it doesn't needs. When exposed form is in block, it also is rendered for view results in content block. When there are attached displays to main one - the form is also rendered for them.
Proposed resolution
In file plugins/views_plugin_exposed_form.inc code from line 162 move into if construct body:
$form = drupal_build_form('views_exposed_form', $form_state);
$output = drupal_render($form);
if (!$this->view->display_handler->displays_exposed() || (!$block && $this->view->display_handler->get_option('exposed_block'))) {
return "";
}
else {
return $output;
}
$form = drupal_build_form('views_exposed_form', $form_state);
if (!$this->view->display_handler->displays_exposed() || (!$block && $this->view->display_handler->get_option('exposed_block'))) {
return "";
}
else {
return drupal_render($form);
}
Comments
Comment #1
pjcdawkins commentedHm yes that does seem to be unnecessary. I had a look and perhaps there's a further improvement - see attached patch.
Comment #2
dewalt commentedThe last improvement has a defect - form should be processed, to get values from user's input. Only render operation is
unnecessary.
Comment #3
pjcdawkins commentedOK, well here's a patch for the change you suggest.
But since I don't understand what's going on in this code, I think we at least need some comments.
Comment #4
dewalt commentedI'll insert you patch with correct issue status.
Comment #5
dewalt commentedOops, I'll try one more time :)
Comment #6
chris matthews commentedThe 5 year old patch in #5 to views_plugin_exposed_form.inc applied cleanly to the latest views 7.x-3.x-dev and if still applicable need review.
Comment #7
tonytheferg commentedWe have a similar problem in drupal 8/9. Anyone have a suggestion as to where to start with this?
drupal_renderis deprecated in D8,In
ExposedFormPluginBase@
namespace Drupal\views\Plugin\views\exposed_form;I tried as a stab in the dark, replacing
return $formwithreturn \Drupal::service('renderer')->render($form);Got the following error.
Error: Cannot use object of type Drupal\Core\Form\FormState as array in Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (line 134 of *\web\core\modules\views\src\Plugin\views\exposed_form\ExposedFormPluginBase.php)Comment #8
renatog commentedIt really makes sense
@tonytheferg
As this project is for D7 only on this case for D8 and D9 you can move your question here
https://www.drupal.org/project/issues/drupal?version=any_9.&component=vi...
Comment #10
renatog commentedMoved to the dev branch
Comment #11
tonytheferg commented@RenatoG, I marked this as a parent of a similar issue for 8/9.
https://www.drupal.org/project/drupal/issues/3031259
Comment #12
damienmckenna