Option for _none is removed once a field has a value and can cause accidental data corruption

Created on 19 November 2019, over 4 years ago
Updated 28 February 2023, over 1 year ago

When you create a required single-value entity reference field, for example a term reference, then the referenced entity is deleted, the _none option disappears. When the widget is loaded up it defaults to the first option in the list, and the user can easily save the new value without noticing. Steps to reproduce below.

  1. Install Drupal with the standard profile
  2. Change the Tags field to Required, Allowed number of values to 1
  3. Change the Tags widget to Select list
  4. Create two terms in the Tags vocabulary, "foo" and "bar"
  5. Create an article node, set the Tags field to "foo"
  6. Delete the "foo" term
  7. Edit the article node, the widget now has "bar" selected
  8. Save the article node

I believe this tracks back to OptionsSelectWidget::getEmptyLabel() which checks for !$this->hasValue. It doesn't consider whether the stored value is actually present in the available options.

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
OptionsΒ  β†’

Last updated 27 days ago

No maintainer
Created by

πŸ‡¦πŸ‡ΊAustralia mstrelan

Live updates comments and jobs are added and updated live.
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.

Production build 0.69.0 2024