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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rjacobs’s picture

Status: Active » Needs review
FileSize
1.99 KB

Here'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.

rjacobs’s picture

Issue summary: View changes

Added note about another related application (add titles/headings to list).

vasike’s picture

Status: Needs review » Needs work

it seems the patch won't apply anymore.
@rjacobs: could you, please, update your patch.
Thank you

rjacobs’s picture

Status: Needs work » Needs review
FileSize
1.53 KB

The 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.

  • vasike committed a49c603 on authored by rjacobs
    Issue #2337677 by rjacobs, vasike: DX request: add hook to allow...
vasike’s picture

Status: Needs review » Fixed

Commited
@rjacobs Thank you, Sir.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.