| Project: | Drupal core |
| Version: | 8.x-dev |
| Component: | field system |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
Right now widget plugins can specify in their annotation that they are 'multiple_values' (like: "don't repeat myself, on single copy can handle input of multiple values").
This is used for things like option widgets (checkboxes/radio, select) or the taxo autocomplete widget.
WidgetBase::form() uses this property to call formSingleElement() directly, or formMultipleElements() to "repeat N copies of the widget".
The not-too-nice thing is, the content of WidgetBase::submit() currently only really makes sense for stuff that went through formMultipleElements().
I'm thinking It would probably be cleaner to provide a separate MultipleWidgetBase base class for 'multiple' widgets, and get rid of the 'multiple_values' entry in the widget info. Widgets that are 'multiple' just extend from MultipleWidgetBase instead of WidgetBase.
Comments
#1
Would it make sense to extend vertically?
OptionsWidgetextends MultipleWidgetBase
extends WidgetBase
Or perhaps even reversed?
OptionsWidgetextends WidgetBase
extends MultipleWidgetBase
I don't know the internals enough, so don't know which of both bases is actually more specific than the other.
#2
Probably one or the other, yes.
But not too sure which one before looking at some actual code :-)
#3
Wrote big piece of this friday. but didn't post a patch yet. I went for the first case. Re-rolling it now at latest state.
#4
Updated patch. The 'Store field information in $form_state.' and 'Populate widgets with default values when creating a new entity.' should probably move to a seperate method of WidgetBase. Now that code is duplicated.
#5
#6
The last submitted patch, 1846162-4-MultipleWidgetBase.patch, failed testing.
#7
#4: 1846162-4-MultipleWidgetBase.patch queued for re-testing.
#8
The last submitted patch, 1846162-4-MultipleWidgetBase.patch, failed testing.