Use Options views filter for list fields with allowed_values_function callback

Created on 1 March 2018, over 6 years ago
Updated 26 December 2023, 11 months ago

Problem/Motivation

Drupal core ships with several list field storage, for example 'List (text)', 'List (integer)'. These fields allow the site administrator to enter allowed values from the UI. These fields also support an 'allowed_values_function' callback as an alternative to hardcoding these values.

When using an allowed_values_function, the Views filter differs from the allowed_values version as well as the Drupal core views filtering.

Allowed values:

β†’

Allowed values callback:

β†’

Proposed resolution

Use the Options views filter for fields with an allowed_values_function, so a filter can have multiple values.

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

The Views UI shows the Options filter for fields with an allowed_values_function.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Needs work

Version

1.0

Component

Views integration

Created by

πŸ‡³πŸ‡±Netherlands idebr

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Wrote/rerolled the patch for search_api 1.29.0

    I wrote the patch before finding this issue, in hindsight in exactly the same way as the already existing patches. Could this patch be merged, so we don't have to keep rerolling it: the patch is a clean solution. I'm using it in production on a Drupal 9.5.7.

  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    @ sboden: Same as for the old patch, this is missing tests and an upgrade path.

  • Tests are missing, ok.

    For the upgrade path, that might be tricky. But, when you define a field with allowed_values_function, you can't use allowed_values in the Drupal GUI anymore - the options are mutually exclusive. So the patch is actually "new" functionality: without the patch search_api would only take allowed_values into account, after the patch allowed_values_function is also taken into account which people who defined a field as such would want to use. When allowed_values_function is filled in, allowed_values is empty anyway.

    Are there people who defined a filter on a field using allowed_values_function but assume users will filter using its key as search criteria (without dropdown), I doubt it. That's e.g. why I ended up on this issue.

  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    As described in #7, even if this is likely the expected behavior in general, specifically at an update this might break people’s views, which should really be avoided, if possible. Especially for a new feature, not a bug fix.

  • πŸ‡»πŸ‡³Vietnam linhnm

    Re-rolled for 1.31

Production build 0.71.5 2024