Field item's getSettableOptions() method doesn't have access to the current value

Created on 6 December 2015, almost 9 years ago
Updated 9 February 2023, over 1 year ago

OptionsProviderInterface has the following in its docblock:

 * For example, in an workflow scenario, the settable values for a state field
 * might depend on the currently set state, while possible values are all
 * states. Thus settable values would be used in an editing context, while
 * possible values would be used for presenting filtering options in a search.

Great, that's precisely what I'm doing, creating a state field, and returning the next allowed states in getSettableOptions().
However, turns out that the field value is empty/unpopulated, and that I need to do:

$field_name = $this->getFieldDefinition()->getName();
$value = $this->getEntity()->{$field_name}->value;

This is obviously a bug that occurs when creating a cloned field instance.
Here's the call stack:
- OptionsSelectWidget::formElement
- OptionsWidgetBase::getOptions
- FieldStorageConfig::getOptionsProvider
- FieldTypePluginManager::createFieldItem
- TypedDataManager::getPropertyInstance

Looks like the bug occurs in TypedDataManager. The FieldTypePluginManager passes $items which contains the value, but typed data manager's getPropertyInstance() doesn't seem to do anything with it (it has its own $value argument which FieldTypePluginManager is not passing).

🐛 Bug report
Status

Active

Version

8.9 ⚰️

Component
Typed data 

Last updated 2 days ago

  • Maintained by
  • 🇦🇹Austria @fago
Created by

🇷🇸Serbia bojanz

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.71.5 2024