Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi
Form alter is called twice when filter are exposed in a block, form alter can access view object correctly on first call, in second call it's empty
Steps to reproduce
1> create a view of page type
2> select any of the filters to be exposed ,
3> Under Exposed form ,select Exposed form in block to YES,
4> Place the block on any region on the page
5> write a form_alter in custom module, the exposed form will be called twice, once where view query object is there , and one where it is null
Thanks,
Namit Garg
Comment | File | Size | Author |
---|---|---|---|
first alter.png | 323.37 KB | namit.garg | |
second alter.png | 276.9 KB | namit.garg | |
exposed error in views.png | 334.17 KB | namit.garg |
Comments
Comment #2
MustangGB CreditAttribution: MustangGB commentedComment #8
tonytheferg CreditAttribution: tonytheferg commentedI think it is related to this issue from drupal 7. I am seeing the same thing. Putting an exposed search form in a block, and logging the submission reults in 3 for me, I think one for the master display, one for the page, and one for the form in the block.
My comment from this issue:
https://www.drupal.org/project/views/issues/2088549
We have a similar problem in drupal 8/9. Anyone have a suggestion as to where to start with this?
drupal_render
is deprecated in D8,In
ExposedFormPluginBase
@
namespace Drupal\views\Plugin\views\exposed_form;
I tried as a stab in the dark, replacing
return $form
withreturn \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 #9
tonytheferg CreditAttribution: tonytheferg commented