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.

Files: 
CommentFileSizeAuthor
#6 added_hooks_1887298.patch1.13 KBMadzgo
Test request sent.
[ View ]
#1 bef_example_widget.zip633 bytesMadzgo
#1 better_exposed_filters.zip38.79 KBMadzgo

Comments

StatusFileSize
new38.79 KB
new633 bytes

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

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.

@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).

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")

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! :)

Issue summary:View changes

Added note about plian old form alter as an alternative.

Issue summary:View changes
StatusFileSize
new1.13 KB
Test request sent.
[ View ]

Status:Active» Needs review

Added a patch with changes from #1