hook_form_views_exposed_form_alter() called multiple times - for every filter

Created on 5 March 2024, 10 months ago

Problem/Motivation

As title says hook_form_views_exposed_form_alter() called multiple times - for every filter built.
So there could be multiple code runs within form alter runs ... which is "not ideal"

Steps to reproduce

- Build a view with multiple filters that use this module options.
- Implement a hook_form_views_exposed_form_alter() for this view and check how many calls/executions take place.

Proposed resolution

Find a way to have, at least, control in the alter hook, not to have multiple code runs.

User interface changes

- none -

API changes

-

Data model changes

-

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇷🇴Romania vasike Ramnicu Valcea

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @vasike
  • Status changed to Needs review 10 months ago
  • 🇷🇴Romania vasike Ramnicu Valcea

    First: very nice module - good idea, so thanks

    There is a new MR that tries to solve this.
    However it doesn't eliminate multiple calls ... but it limit to 2 calls only
    + to have control in the alter hook with new form property $form['#selective_bef_view'].

    I hope it helps.

  • 🇷🇴Romania vasike Ramnicu Valcea

    It seems them MR "solution" it doesn't work "properly" ... as for all the filters to work it's need to have this view built and executed every time.

    However, from Drupal\selective_better_exposed_filters\Plugin\better_exposed_filters\filter\SelectiveFilterBase
    there is a view property that could be used in hook_form_views_exposed_form_alter() implementation

    Example

    /**
     * Implements hook_form_FORM_ID_alter() for views_exposed_form.
     */
    function custom_module_form_views_exposed_form_alter(array &$form, FormStateInterface $form_state) {
      $view = $form_state->get('view');
      if (empty($view->selective_filter)) {
         // ... "do the alter".
      }
    }
    

    Question1: isn't easier as $form property
    Ex. $form['#original_views_exposed_form'] = TRUE;

    Question2: What about document this issue, README file and/or project page info.

    Changed the issue Category to Support request
    And status keep it Needs Review ... for now

    p.s. sorry for the noise.

  • 🇬🇧United Kingdom c_archer Cumbria

    Has there been any progress with this?

Production build 0.71.5 2024