Problem/Motivation

Since 2.0.4 the widget never preselects stored values. Edit forms show
"- None -", and the next save wipes the value.

#3517342 made getOptions() return an empty array, assuming the options
are never used. They are: OptionsSelectWidget::formElement() sets
'#default_value' => $this->getSelectedOptions($items), and
OptionsWidgetBase::getSelectedOptions() filters stored values against
that list. Empty list, nothing matches, no default value.

Affects 2.0.4 - 2.0.7. Not 2.0.3, not 3.0.x.
Same bug as #17 in #3613802 (that issue is otherwise about the D10
getBundleListCacheTags() fatal).

Steps to reproduce

1. Entity reference field to a vocabulary, widget "Simple hierarchical select".
2. Create node, select a term, save.
3. Edit: widget shows "- None -".
4. Save: value gone.

Proposed resolution

Override getSelectedOptions() to return the stored values unfiltered.
The #3517342 optimisation stays intact - the option list is still never
loaded.

Patch attached with a kernel test. Drupal 11.4.5 / PHP 8.3, shs 2.0.7,
phpcs clean.

CommentFileSizeAuthor
shs_preselect_stored_values.patch6.59 KBcarlitus

Comments

carlitus created an issue. See original summary.

greenskin’s picture

Priority: Normal » Critical

Patch applies and looks to work.

serverjohn’s picture

I am having the same issue as described. The patch resolves the issue.