Note: This needs better documentation, tests, ... It is just a first "working" patch, because I try to be a good contributor and I'd like to have some feedback about the idea/workflow ;) (http://webchick.net/embrace-the-chaos)
Provide a flexible, generic, Filter DB Extender which allows to filter listings, for example admin/user/user and admin/content/node.
Core currently has several of these slightly different filter forms, each with its own form definition, css, ugly query builder functions and so on. They are pretty hardcoded, other modules can't extend them. (for example, node currently needs to define taxonomy stuff: http://api.drupal.org/api/function/node_build_filter_query/7).
What are the advantages?
- Extendable: Other modules can provide additional filter, which can be as complex as they want it to be
- Shared code, same UI/Look & Feel
- Easy to implement for additional listings (I hope.. )
- Actually working multi-value support (for example, admin/user/user seems to be pretty broken). Filters can either only allow a single value (a new filter would override the existing) or multiple values (a new filter extends the existing), just by defining multiple => TRUE.
How does it work?
- Extend query:
- Define a unique name:
- Define your filters in
- Either extend an existing form with
$form['filter'] = $query->getForm()or use the helper function drupal_get_form('filter_extender_form', $query)
How does the filtering work?
Simple conditions: just define a key 'field' in your hook and Filter will add conditions for it, like $query->condition($field, $value).
Advanced filter: Filter automatically adds a tag "filter_filtername" and adds the currently active filters and filter elements as metadata, so a module can implement hook_query_filtername_alter() and do the advanced stuff there.
What this patch currenty does:
- Implement a Filter Db Extender class
- Replace admin/user/user with this class
- Uses the user_filters theme as base and changes it a bit (Note: This really needs UX/Accessibility help and review)