From: Simon Green Date: Sun, 10 Aug 2014 07:42:10 +0000 (+1000) Subject: Bug 897915 - Field lists not sorted alphabetically X-Git-Tag: bugzilla-4.5.6~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4b9806c5ab5e63383269ef328643145ade66004;p=thirdparty%2Fbugzilla.git Bug 897915 - Field lists not sorted alphabetically r=dkl, a=sgreen --- diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index b36249b2f2..52ccee593c 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -611,6 +611,21 @@ $Template::Stash::LIST_OPS->{ clone } = return [@$list]; }; +# Allow us to sort the list of fields correctly +$Template::Stash::LIST_OPS->{ sort_by_field_name } = + sub { + sub field_name { + if ($_[0] eq 'noop') { + # Sort --- first + return ''; + } + # Otherwise sort by field_desc or description + return $_[1]{$_[0]} || $_[0]; + } + my ($list, $field_desc) = @_; + return [ sort { lc field_name($a, $field_desc) cmp lc field_name($b, $field_desc) } @$list ]; + }; + # Allow us to still get the scalar if we use the list operation ".0" on it, # as we often do for defaults in query.cgi and other places. $Template::Stash::SCALAR_OPS->{ 0 } = diff --git a/t/011pod.t b/t/011pod.t index c3ec39898d..fc66bca63b 100644 --- a/t/011pod.t +++ b/t/011pod.t @@ -32,6 +32,7 @@ use constant SUB_WHITELIST => ( 'Bugzilla::FlagType' => qr/^sqlify_criteria$/, 'Bugzilla::JobQueue' => qr/(?:^work_once|work_until_done|subprocess_worker)$/, 'Bugzilla::Search' => qr/^SPECIAL_PARSING$/, + 'Bugzilla::Template' => qr/^field_name$/, ); # These modules do not need to be documented, generally because they diff --git a/template/en/default/search/boolean-charts.html.tmpl b/template/en/default/search/boolean-charts.html.tmpl index 901de05019..bfb4e7bf1b 100644 --- a/template/en/default/search/boolean-charts.html.tmpl +++ b/template/en/default/search/boolean-charts.html.tmpl @@ -134,7 +134,15 @@ id="f[% cond_num FILTER html %]" onchange="fix_query_string(this)" class="custom_search_form_field"> - [% FOREACH field = fields %] + [%# Turn the array in to a hash with the name as the key %] + [% + field_hash = {}; + FOREACH field IN fields; + field_hash.${field.name} = field; + END; + %] + [% FOREACH field_name = field_hash.keys.sort_by_field_name(field_descs) %] + [% field = field_hash.$field_name %]