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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Would it make sense to extend vertically?

OptionsWidget
extends MultipleWidgetBase
extends WidgetBase

Or perhaps even reversed?

OptionsWidget
extends 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.

yched’s picture

Probably one or the other, yes.
But not too sure which one before looking at some actual code :-)

nils.destoop’s picture

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.

nils.destoop’s picture

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.

nils.destoop’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1846162-4-MultipleWidgetBase.patch, failed testing.

nils.destoop’s picture

Status: Needs work » Needs review

#4: 1846162-4-MultipleWidgetBase.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1846162-4-MultipleWidgetBase.patch, failed testing.

andypost’s picture

e0ipso’s picture

Issue tags: +Field API
FileSize
51.29 KB

New patch from scratch.

This was pair programmed with @plopesc in Szeged.

e0ipso’s picture

Status: Needs work » Needs review

Needs review. Testbot, get to work!

Status: Needs review » Needs work

The last submitted patch, 10: cleanup-widget-api-1846162-10.patch, failed testing.

e0ipso’s picture

Status: Needs work » Needs review
FileSize
54.69 KB

Hopefully this will fix the issues from #10.

Common autocomplete functionality (in AutocompleteWidget and AutocompleteTagsWidget) and code was previously abstracted into AutocompleteWidgetBase. Since this issue separates WidgetBase into WidgetBaseSingle and WidgetBaseMultiple we cannot inherit both from the previous base class (AutocompleteWidgetBase) and the new one. Therefore we now have some code duplication between AutocompleteWidget and AutocompleteTagsWidget.

A possible workaround would be to use a trait.

plopesc’s picture

e0ipso’s picture

Status: Needs review » Needs work

The last submitted patch, 14: cleanup-widget-api-1846162-14.patch, failed testing.

e0ipso’s picture

FileSize
54.85 KB

Re-roll of #14.

plopesc’s picture

Status: Needs work » Needs review

Let's go testbot!

Status: Needs review » Needs work

The last submitted patch, 17: cleanup-widget-api-1846162-17.patch, failed testing.

andypost’s picture

Issue tags: +API addition
undertext’s picture

Assigned: Unassigned » undertext
undertext’s picture

Status: Needs work » Needs review
FileSize
46.27 KB

Rerolled.

undertext’s picture

Fixed form_state vars in function declarations.

The last submitted patch, 23: cleanup-widget-api-1846162-23.patch, failed testing.

The last submitted patch, 23: cleanup-widget-api-1846162-23.patch, failed testing.

The last submitted patch, 23: cleanup-widget-api-1846162-23.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 24: cleanup-widget-api-1846162-24.patch, failed testing.

undertext’s picture

Status: Needs work » Needs review
FileSize
54.72 KB

Oh. This one should be ok.

Status: Needs review » Needs work

The last submitted patch, 29: cleanup-widget-api-1846162-29.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.