How can I set exposed filter options programmatically?

Created on 15 September 2023, over 1 year ago

I want a views filter with a select widget and I need to set the options programmatically. It is possible to do this in hook_form_FORM_ID_alter(), however, it doesn't really work as desired. This is because the widget does not respond as expected to the option values I set. Instead, Drupal expects the option values to be group numbers. (See attached screenshot.)

If the actual value I am targeting is 123, there needs to be a group with that value. Thus, it's not possible to set the values in $form['my_field']['#options'] in hook_form_FORM_ID_alter().

πŸ’¬ Support request
Status

Active

Version

9.5

Component
ViewsΒ  β†’

Last updated about 5 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States arnoldbird

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

Comments & Activities

  • Issue created by @arnoldbird
  • Status changed to Closed: outdated 3 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    @arnoldbird, as you can see by the lack of responses here the Drupal Core issue queue is not the ideal place for support requests. The 'support request' option is there for filing support issues for contributed modules and themes. There are several support options listed on our Support page β†’ . This is 'Get Support' at the top of Drupal.org. There is also information about Drupal Slack β†’ , at 'Get Support -> Drupal Slack' also at the top of Drupal.org. You may get better replies in one of those places.

    Cheers

Production build 0.71.5 2024