How can I set exposed filter options programmatically?

Created on 15 September 2023, 10 months 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 29 minutes ago

Created by

πŸ‡ΊπŸ‡ΈUnited States arnoldbird

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

Comments & Activities

Production build 0.69.0 2024