I looked through the issue queue and this doesn't seem to have come up before.

It would be good if BEF allowed other modules to define exposed widgets.

This would mean people could implement any obscure widget they desire without it having to bloat this module with things most people would not need.

It could be done just with a hook system or using something like the ctools plugin API, although I think to go the ctools route the best thing to do would be to convert all of BEF's widgets to plugins also, which would be a huge change and would probably be better of in a new branch.

Which leaves a simpler hook system.

I haven't fully fleshed it out yet but off the top of my head it would need to have:
* Something like a hook_bef_widget_info(), where callbacks etc. can be registered.
* In options_form() there should be a hook so modules can add their widget to the bef_format options. This would pass in the filter so the other module could determine whether or not they can work with that filter.
* A way to add additional options to the options_form for their widget.
* Within exposed_form_alter() modules need to be able to have their own case for the bef_format switch statement, so that a hook or a function they defined in hook_bef_widget_info() is called to do the work. That is also where they can add their own js & css etc.

Also, an addition might be to have something along the lines of hook_bef_widget_alter() for modules to modify other widget behaviour.
However that would be most useful if existing BEF widgets were also implemented via the hook system, in which case we are back to a decent amount of rewriting and might consider the ctools plugin route again.

So I guess the best case scenario is that BEF is more of an exposed filter widget API that also implements a bunch of commonly used widgets (the ones already in the module).

A simpler bolt-on hook system could be up and running faster, which would be nice for me, although it would mean more work in the long run if it was later changed to a full on plugin system and add-on widgets had to be rewritten anyway.

Also, it should be possible to add your own custom widget just using hook_form_alter() functions on the options form and the exposed form, however it seems it would be a nicer solution if it were a plugin system.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Madzgo’s picture

I added 2 hooks that allow you to register widgets and change the form for them.

I attached the better exposed filter module (modified file is better_exposed_filters_exposed_form_plugins.inc)

There is also a test module attached that shows the usage of hooks

yareckon’s picture

Amen! I am looking at forking BEF because I need an extra widget type (bef_links that falls back to select on mobile) and I would LOVE to see a plugin system that would avoid the need to fork.

rooby’s picture

@Madzgo:

Thanks. Any chance you could make a patch of the changes? (see https://drupal.org/node/707484)

@yareckon:
You shouldn't need to fork.

Even without new hooks it should be possible.

You should be able to alter the admin forms and the exposed filter forms to do what you want (from memory I think).

Madzgo’s picture

Sorry, I just don't have enough time these days.

The changes are really simple, just added 4 lines at 2 places in better_exposed_filters_exposed_form_plugins.inc (search for "hook")

mikeker’s picture

I really like this idea: a pluggable system that allow extra widgets to be added as needed. Had I realized how popular BEF would become when I first wrote it, I would've done that from the start!

I haven't had the time to look at the changes proposed in #1 but will try to do so in the near future. If someone has the chance to convert this to a patch, please post it here and set the issue to "needs review". I'm not in the issue queue as often as I would like to be, but NR issues get my immediate attention when I'm here.

To be honest, I can see this being an 8.x issue that may (or may not) get backported to 7.x, mostly because of the systemic changes. But I can be convinced otherwise! :)

mikeker’s picture

Issue summary: View changes

Added note about plian old form alter as an alternative.

Madzgo’s picture

Issue summary: View changes
FileSize
1.13 KB
Madzgo’s picture

Status: Active » Needs review

Added a patch with changes from #1

jkopel’s picture

Status: Needs review » Closed (outdated)

In light of the current maintenance situation we are only going to be doing feature additions in the D8 branch.
I am going close this now, but feel free to reopen it if there is a significant patch to add new functionality.
If you would like to see this or something like it in the D8 branch please resubmit.