I just ran into a Field API limitation over at #1586334: field_extrawidgets makes the default widget for fields "Hidden". That module is providing some advanced widgets for all fields: 'hidden' and 'read-only'. Widgets can have weights relative to a specific field instance, which controls the order of the widget on the entity form. However, since there's no support for weights for the widgets themselves, there's no good way for this contrib module to ensure its widgets come last in the choice of widget in the Field UI. So, once you turn on field_extrawidgets, the default widget for all fields via the Field UI is "Hidden". UI #fail indeed. My hack work-around is to use hook_field_widget_info_alter() so the module advertises its widgets that way and can stuff them at the bottom of the array, but then other modules can't alter its widget info. Ugh.
I was lamenting this fact in IRC and webchick encouraged me to open an issue about it, saying this sort of API addition is potentially backportable to D7. I searched and found nothing, so I hope this isn't duplicate.
Comment | File | Size | Author |
---|---|---|---|
#9 | 1586356-9.field_widget_info_weight.d7.patch | 2.47 KB | amateescu |
#3 | 1586356-1.field_widget_info_weight.patch | 2.49 KB | dww |
#1 | 1586356-1.field_widget_info_weight.patch | 2.49 KB | dww |
#1 | 1586356-1.field_widget_info_weight.d7.patch | 2.47 KB | dww |
Comments
Comment #1
dwwPatches for D8 and D7. Tested on D7 and works nicely.
Comment #3
dwwSorry, I don't know all the fancy ways of the bot these days. Here's just the D8 patch again.
Comment #4
amateescu CreditAttribution: amateescu commentedI was also bothered by the default UX behavior provided by field_extrawidgets, and this patch looks really clean and straightforward to me.
Comment #5
catchThis looks simple enough but let's add a test for it.
Comment #6
dwwWhat exactly is a test supposed to test here?
Do you want a unit test that
uasort($info['widget types'], 'drupal_sort_weight');
does what we expect? That's the *only* change to the code, everything else is comments and docs. I don't follow core's test coverage that closely, but surely we'd already know if that was broken, right?Do you want a functional test that adds dummy widgets and tries to ensure the right order in the field UI? That seems like an awful lot of trouble, especially if we already know drupal_sort_weight() works.
Cheers,
-Derek
Comment #7
yched CreditAttribution: yched commentedI don't think I see where a test would be useful either.
This being said, and while I approve this, this topic about ordering Plugin Implementations (we're working on transforming widgets to Plugins right now - #1742734: [META] Widgets as Plugins) already surfaced in #1512602-9: Write a hook based plugin discovery implementation..
Short version : currently image_effect_definitions() (equivalent of _field_info_collate_types() for image effects) does a ksort on available image effects. It was agreed that a "list of available plugins implementation" has no natural order by itself - i.e the discovery process can do some massaging on each plugin info (like filling in defaults for missing properties), but has no business massaging the list as a whole - and currently the Plugin API doesn't allow this.
If an order makes sense, it's only presentational, and the ordering should be made by the calling code (the UI) - and different places in the UI might each have their own relevant sorting logic, for that matter.
So, I have no problem getting this in as is (image effects currently do something similar), but #1742734: [META] Widgets as Plugins will take the ordering out of the discovery and in the UI code.
Comment #8
catchOK fair enough. Committed/pushed to 8.x, moving to 7.x for backport.
Comment #9
amateescu CreditAttribution: amateescu commentedRe-uploading the D7 patch from #1.
Comment #10
webchickThis seems harmless enough for D7, and helps out d.o as well.
Committed and pushed to 7.x. Thanks!
Comment #12
David_Rothstein CreditAttribution: David_Rothstein commentedThis is a neat little feature addition; seems worth mentioning in CHANGELOG.txt and the release notes.