From 8f9a321b26d53b8669dac7775e82738a3f42c532 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Mon, 28 Sep 2015 12:00:10 +0000 Subject: [PATCH] Bug 14912: Sort Advanced Search Languages by priority MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Libraries should be able to control the priority of languages in the advanced search drop-down list. This could be achieved by sorting them according to the AdvancedSearchLanguages system preference. To test: -1. Set some languages into AdvancedSearchLanguages system preference 1. Go to advanced search and look at Languages drop-down list 2. Note that the list is in alphabetical order 3. Apply patch 4. Repeat step 1 5. Note that the list is sorted like AdvancedSearchLanguages Works as expected Signed-off-by: Marc VĂ©ron --- C4/Languages.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index 384fd7a..b3f377e 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -205,6 +205,7 @@ sub getLanguages { my $isFiltered = shift; my @languages_loop; + my $languages_hash; my $dbh=C4::Context->dbh; my $default_language = 'en'; my $current_language = $default_language; @@ -251,9 +252,18 @@ sub getLanguages { } # Do not push unless valid iso639-2 code if ( $language_subtag_registry->{ iso639_2_code } and ( !$language_list || index ( $language_list, $language_subtag_registry->{ iso639_2_code } ) >= 0) ) { - push @languages_loop, $language_subtag_registry; + $languages_hash->{$language_subtag_registry->{ iso639_2_code }} = $language_subtag_registry; + push @languages_loop, $language_subtag_registry if not $language_list; } } + if ($language_list) { + # sort @languages_loop into order defined in AdvancedSearchLanguages preference + my @adv_search_languages = split /[,|]+/, $language_list; + foreach my $adv_search_lang (@adv_search_languages){ + push @languages_loop, $languages_hash->{$adv_search_lang} if $languages_hash->{$adv_search_lang}; + } + } + return \@languages_loop; } -- 1.7.10.4