Problem/Motivation
Uncovered while working on #3165990: UX bug with the duration widget for date-only ranges. That issue is trying to fix a FieldWidget for datetime_range fields to deal with weirdness when the widget is used on a date-only daterange field. The date-only aspect is a property of the field storage definition. Ideally, the widget would advertise / use different default settings depending on if the field it's attached to is datetime or date-only.
Sadly, PluginSettingsBase::defaultSettings() is public static (without a class instance), and gets no context passed in. So it's currently impossible to do this in a clean way.
Steps to reproduce
Try to have different values for defaultSettings() based on the field definition or field storage definition the widget or formatter is attached to.
Proposed resolution
The B/C implications of changing defaultSettings() itself would be monstrous. Every implementation calls parent::defaultSettings(), this is implemented dozens of times in core and perhaps 1000s of times in contrib.
Instead, let's add a parallel version that gets passed the fieldDefinition.
Sadly, PluginSettingsBase doesn't have the fieldDefinition. That currently lives directly in FormatterBase and WidgetBase. But those two seem to be the only things extending PluginSettingsBase, so I think we can just move those two protected members up in the class hierarchy. ;)
Remaining tasks
- Upload the initial patch.
- Discuss naming, structure, etc.
- Add some tests to prove this works as intended.
- Reviews / refinements.
- RTBC.
- Commit.
- Fix contrib modules like datetime_extras that wish this exists.
User interface changes
Nothing directly. Field plugins might present different default settings based on field definitions.
API changes
TBD.
Data model changes
N/A
Release notes snippet
TBD.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3166481-2.patch | 3.73 KB | dww |
Comments
Comment #2
dwwDefinitely NW, but to get us started, here's a totally untested version. Curious if the bot blows up at all with this. Would love feedback on the approach before spending much more time on this.
Thanks!
-Derek
Comment #8
smustgrave commentedFirst thanks for the super details issue summary helped out a lot!
Just queued #2 for 10.1.x tests also.
Moving to NW for the additional discussion and path forward.