1

When we set options for a views grouped filter using the views GUI, the select input's option values do not match the values we set in the GUI.

For example, if we use the GUI to set the Grouping 1 label to "My Test" and the Grouping 1 value to 321, then save the view and inspect the resulting select element, we see that the My Test select option has a value of 1, not 321. The view works fine because Drupal knows that option 1 corresponds to a value of 321.

However, now I want to preprocess the options programmatically. I see how to populate some options in hook_form_views_exposed_form_alter(), but how do I know what values to set? Intuitively, it would seem we should set the option keys to the actual value we are targeting, but we already know from using the GUI that that is not how exposed view filters work. In other words, we can't do this...

$options[321] = "My Test";
$form['my_form']['#options'] = $options;

Instead, we need to know what value Drupal expects the option to have. How can I determine what that value should be so that I can set the select options programmatically?

Drupal version: 9.5.1

4
  • This may be asking the wrong question. Views module has 37 hooks of its own. Have you tried them?
    – cilefen
    Sep 5, 2023 at 17:40
  • Hopefully it's clear what my goal is. I want to programmatically set the options for a views exposed filter. What would be the best hook to use for doing this? Thanks.
    – arnoldbird
    Sep 7, 2023 at 12:21
  • Maybe this question will work better: drupal.stackexchange.com/questions/316932/…
    – arnoldbird
    Sep 7, 2023 at 12:41
  • @cilefen I tried hook_views_pre_view() and hook_views_pre_execute() today with no success.
    – arnoldbird
    Sep 7, 2023 at 14:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.