hook_form_views_exposed_form_alter() called multiple times - for every filter

Created on 5 March 2024, 4 months ago
Updated 7 March 2024, 4 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

-

πŸ’¬ Support request
Status

Needs review

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 4 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.

Production build 0.69.0 2024