Stale field settings used by options_allowed_values prevents widgets from updating the allowed values.

Created on 2 January 2016, over 9 years ago
Updated 20 January 2023, about 2 years ago

Problem/Motivation

While working on a select or other implementation for list fields. I got blocked by the fact that options_allowed_values uses stale field settings to determine it's allowed values. This creates a problem because select or other adds a new option to the field settings upon form submission, which should then be picked up by AllowedValuesConstraintValidator. But AllowedValuesConstraintValidator uses options_allowed_values, which uses the stale field settings to produce a list of options without the newly added option.

I will work on a test which demonstrates the problem, but in the mean time, the attached patch fixes it.

Proposed resolution

Change the behavior of list field items so that the field definition is always fetched from storage when getting the allowed values so that the instance object does not store stale data.

Alternatives

1. Contrib module the allowed values constraint plugin (each module does this making a module incompatible with each other).
2. Contrib module migrates list fields to text fields, provides duplicate code to handle allowed values, migrates back on uninstall.
3. Contrib module obliterates list field type plugins and replaces with its own code that does not use allowed values option (the nuclear option).
4. Contrib module does not use list fields and site builders that want to use the module must do so before deciding their entity architecture and cannot swap out to a widget without re-architecting and migrating data (seemingly not a good user experience).
5. Contrib module similar to conditional field can work with multiple fields (not as seamless as one field for things such as views integration, data export).

Remaining tasks

- Priority
- Performance Impact?

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Needs work

Version

10.1

Component
Field 

Last updated 3 days ago

Created by

🇳🇱Netherlands legolasbo Middelburg

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

No activities found.

Production build 0.71.5 2024