It looks like it's currently impossible to make alterations to the json returned by views_autocomplete_filter(). I'm thinking it would really be useful to offer a hook here so other modules can make alterations.
I realized that the results returned are generated by views, which is hugely customizable, flexible and an all-around fantastic tool, but there are potential use cases where results acquired from views may need other alterations within the context of this module. For example:
- Programmatic customization of empty results messages (too few characters or no results returned). Those messages can be statically changed with a string override, but not programmatically. See also: #2093553: Customize empty result message programmatically .
- Removal of empty results behavior for custom applications where this does not make sense.
- Allowing the ability for selective theming of individual match results. A theme function may also be useful for the individual match results, but that's probably another topic entirely, for now I'm just interested in opening the door for alterations.
- Allowing the addition of match results, or headers/titles for groups or match results. See also #2285637: Show title above result list.
- Very specialized cases where match results need to be customized beyond the views result set.
I know this would add an extra function call to each lookup, but something like a drupal_alter() should be a totally negligible addition as far as performance is concerned.
Comment | File | Size | Author |
---|---|---|---|
#4 | views_autocomplete_filters-add_alter_hook_for_matches-2337677-4.patch | 1.53 KB | rjacobs |
Comments
Comment #1
rjacobs CreditAttribution: rjacobs commentedHere's a patch that add a drupal_alter() as noted. It also includes a views_autocomplete_filters.api.php file addition for documentation as per standards.
It would be interesting to hear back from a maintainer on this idea.
Comment #2
rjacobs CreditAttribution: rjacobs commentedAdded note about another related application (add titles/headings to list).
Comment #3
vasikeit seems the patch won't apply anymore.
@rjacobs: could you, please, update your patch.
Thank you
Comment #4
rjacobs CreditAttribution: rjacobs at Center for Research Libraries commentedThe patch still applies fine if you allow for an offset, so structurally I think everything is still fine.
Anyway, here's a re-roll sans offset.
Comment #6
vasikeCommited
@rjacobs Thank you, Sir.