Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is one of the sub-tasks of #1742734: [META] Widgets as Plugins to convert all core widgets. This is currently explicitly postponed.
Comment | File | Size | Author |
---|---|---|---|
#14 | 1751244-14-taxonomy_autocomplete_widget.patch | 673 bytes | nils.destoop |
#10 | 1751244-taxonomy_autocomplete_widget-10.patch | 6.99 KB | pcambra |
#6 | 1751244-taxonomy_autocomplete_widget-6.patch | 4.11 KB | pcambra |
#4 | 1751244-taxonomy_autocomplete_widget-4.patch | 4.39 KB | pcambra |
Comments
Comment #1
pcambraOne widget here: 'taxonomy_autocomplete'
Comment #2
swentel CreditAttribution: swentel commentedWidget plugins patch is in, we can convert. The way that we have been working for now is creating a separate branch in the sandbox, but I'm not sure if that's the 'right' way now. Attaching patches is fine as well I guess, once they're ok, we can move this to the core queue.
Comment #3
pcambraI'm giving this one a try tonight
Comment #4
pcambraHere's the conversion, some comments
I haven't converted the info alter as the option widgets haven't been converted yet #1751234: Convert option widgets to Plugin system
Also I've converted
To
multiple_values = TRUE
as the testfields do.Comment #5
yched CreditAttribution: yched commentedRight, taxonomy_field_widget_info_alter() should stay untouched for now.
All references to $instance['widget']['settings'][$some_setting] should move to $this->getSetting($some_setting);
Which means we don't need
in formElement().
Also, errorElement() just replicates WidgetBase::errorElement(), meaning it could be discarded.
Comment #6
pcambraRight, here's a new patch with the changes applied.
Comment #7
yched CreditAttribution: yched commentedSeems to work fine !
As an additional nicety, taxonomy_autocomplete_validate() could be replaced with the new Widgetinterface::massageFormValues() method.
Comment #8
pcambraLet's see how that works :)
Comment #9
yched CreditAttribution: yched commentedOops, sorry - completely removing the #element_validate won't work, because WidgetBase::submit() expects to receive form values as an array, and transforming the comma-separated string into an array happens in taxonomy_autocomplete_validate().
Then I guess taxonomy_autocomplete_validate() could be simplified to just explode the string to an array, and the rest of the logic could go in massageFormValues().
Getting rid of taxonomy_autocomplete_validate() completely would probably require some upstream work on how WidgetBase deals with 'multiple' widgets, that would be a followup.
Comment #10
pcambraApplying the change suggested in #9 and moving to core to see what the TestBot thinks :)
Comment #11
yched CreditAttribution: yched commentedYup, this looks great. Thanks !
Comment #12
webchickAwesome. Confirmed this is basically just moving code around. This is actually a great patch for demonstrating how to convert to the new widget system, and it's nice to see how this more elegantly groups like code together. Well done!
Committed and pushed to 8.x. Thanks!
Comment #14
nils.destoop CreditAttribution: nils.destoop commentedThere was 1 thing that was not converted yet. The field types key from hook_field_widget_info_alter() should now be field_types. Don't know if we need a test for it? Test would be almost the same like the test for #1817180: Tests: hook_widget_info_alter() is not called anymore.
Comment #15
webflo CreditAttribution: webflo commentedLooks good.
Comment #16
catch#14: 1751244-14-taxonomy_autocomplete_widget.patch queued for re-testing.
Comment #17
catchCommitted/pushed to 8.x, thanks!