From d94865b30a92be8a3a900f8d1d8262d36044b1ca Mon Sep 17 00:00:00 2001 From: Tiago Mello Date: Tue, 24 Aug 2010 18:03:20 -0300 Subject: Bug 583243: Add a new hook 'search_operator_field_override'. r/a=mkanat --- Bugzilla/Hook.pm | 23 +++++++++++++++++++++++ Bugzilla/Search.pm | 23 ++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index e00289344..789ad8740 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -433,6 +433,29 @@ The definition is structured as: =back +=head2 search_operator_field_override + +This allows you to modify L, +which determines the search functions for fields. It allows you to specify +custom search functionality for certain fields. + +See L for reference and see +the code in the example extension. + +Note that the interface to this hook is B and it may change in the +future. + +Params: + +=over + +=item C - See L to get +an idea of the structure. + +=item C - The L object. + +=back + =head2 bugmail_recipients This allows you to modify the list of users who are going to be receiving diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index cde1f8e35..0a5b5eb22 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -1597,16 +1597,17 @@ sub do_search_function { return if $args->{term}; } - my $override = OPERATOR_FIELD_OVERRIDE->{$actual_field}; + my $operator_field_override = $self->_get_operator_field_override(); + my $override = $operator_field_override->{$actual_field}; if (!$override) { # Multi-select fields get special handling. if ($self->_multi_select_fields->{$actual_field}) { - $override = OPERATOR_FIELD_OVERRIDE->{_multi_select}; + $override = $operator_field_override->{_multi_select}; } # And so do attachment fields, if they don't have a specific # individual override. elsif ($actual_field =~ /^attachments\./) { - $override = OPERATOR_FIELD_OVERRIDE->{attachments}; + $override = $operator_field_override->{attachments}; } } @@ -1671,6 +1672,22 @@ sub _pick_override_function { return $search_func; } +sub _get_operator_field_override { + my $self = shift; + my $cache = Bugzilla->request_cache; + + return $cache->{operator_field_override} + if defined $cache->{operator_field_override}; + + my %operator_field_override = %{ OPERATOR_FIELD_OVERRIDE() }; + Bugzilla::Hook::process('search_operator_field_override', + { search => $self, + operators => \%operator_field_override }); + + $cache->{operator_field_override} = \%operator_field_override; + return $cache->{operator_field_override}; +} + ########################### # Search Function Helpers # ########################### -- cgit v1.2.3-24-g4f1b