From 4496267b0d1853f6d799d79ad310b36dbcffdb56 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 30 Jan 2025 16:48:40 +0100 Subject: [PATCH] Bug 36081: Use multivalue_preference C4::Context->multivalue_preference is not used so far and split on | However the values of "multiple" sysprefs are separated by... comma! Let support both here. This patch also removes silly JS code in the template. Signed-off-by: Magnus Enger --- C4/Context.pm | 6 +++-- Koha/ArticleRequest.pm | 7 +++--- Koha/Template/Plugin/Koha.pm | 5 ++++ .../admin/preferences/circulation.pref | 5 +++- .../en/modules/opac-request-article.tt | 24 ++++++++----------- t/Context.t | 5 +++- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index bb3080ffde..63dcb6773a 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -318,9 +318,11 @@ sub multivalue_preference { my ( $self, $preference ) = @_; my $syspref = $self->preference($preference) // q{}; - my $values = [ split qr{\|}, $syspref ]; - return $values; + return [ split qr{\|}, $syspref ] + if $syspref =~ qr{\|}; + + return [ split qr{,}, $syspref ] } =head2 enable_syspref_cache diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm index d7c6e6fc30..33421fbb3a 100644 --- a/Koha/ArticleRequest.pm +++ b/Koha/ArticleRequest.pm @@ -268,10 +268,9 @@ sub store { if ( !$self->in_storage ) { $self->created_on( dt_from_string() ); } - my $format = $self->format; - if ( C4::Context->preference('ArticleRequestsSupportedFormats') !~ /\b$format\b/ ) { - Koha::Exceptions::ArticleRequest::WrongFormat->throw; - } + + Koha::Exceptions::ArticleRequest::WrongFormat->throw + unless grep { $_ eq $self->format } @{ C4::Context->multivalue_preference('ArticleRequestsSupportedFormats') }; return $self->SUPER::store; } diff --git a/Koha/Template/Plugin/Koha.pm b/Koha/Template/Plugin/Koha.pm index 7b836afd54..d33e2b08b0 100644 --- a/Koha/Template/Plugin/Koha.pm +++ b/Koha/Template/Plugin/Koha.pm @@ -70,6 +70,11 @@ sub Preference { return C4::Context->preference($pref); } +sub MultivaluePreference { + my ( $self, $pref ) = @_; + return C4::Context->multivalue_preference( $pref ); +} + =head3 CSVDelimiter The delimiter option 'tabs' is stored in the DB as 'tabulation' to avoid issues diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 7192181ea4..e380c2fa0e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -1403,7 +1403,10 @@ Circulation: - - "The following article request formats are supported:" - pref: ArticleRequestsSupportedFormats - - ". Valid choices are currently: PHOTOCOPY and SCAN. Separate the supported formats by a vertical bar. The first listed format is selected by default when you request via the OPAC." + multiple_sortable: + PHOTOCOPY: Photocopy + SCAN: Scan + - "The first listed format is selected by default when you request via the OPAC." Item bundles: diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt index d14bf15657..16a27cb58b 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt @@ -154,13 +154,21 @@ + [% SET ArticleRequestsSupportedFormats = Koha.MultivaluePreference('ArticleRequestsSupportedFormats') %] + [% IF ArticleRequestsSupportedFormats.size %]
  • + [% END %] [% IF AllPublicBranches.size > 1 %]
  • @@ -317,18 +325,6 @@ } }); - // Initialize format(s) - var supported_formats = "[% Koha.Preference('ArticleRequestsSupportedFormats') | html %]"; - if( !supported_formats.match(/PHOTOCOPY/) ) - $('#format option[value="PHOTOCOPY"]').remove(); - if( !supported_formats.match(/SCAN/) ) - $('#format option[value="SCAN"]').remove(); - - if( $('#format option').length > 1 ) { - // Select first listed format - var first_format = supported_formats.split('|')[0].replace(/^\s*|\s*$/g, ''); - $('#format option[value="'+first_format+'"]').attr('selected', true); - } }); [% END %] diff --git a/t/Context.t b/t/Context.t index af37e46830..c49bc9957c 100755 --- a/t/Context.t +++ b/t/Context.t @@ -60,7 +60,7 @@ subtest 'yaml_preference() tests' => sub { subtest 'multivalue_preference() tests' => sub { - plan tests => 3; + plan tests => 4; t::lib::Mocks::mock_preference( 'MultiValuedSyspref', '' ); is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [] ); @@ -70,6 +70,9 @@ subtest 'multivalue_preference() tests' => sub { t::lib::Mocks::mock_preference( 'MultiValuedSyspref', 'some|more|values' ); is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [ 'some', 'more', 'values' ] ); + + t::lib::Mocks::mock_preference( 'MultiValuedSyspref', 'some,more,values' ); + is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [ 'some', 'more', 'values' ] ); }; subtest 'needs_install() tests' => sub { -- 2.34.1