From 03e4c0bf5dbbea74573e0785a9f7b0fa1f3e9738 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 22 Oct 2019 14:58:52 +0100 Subject: [PATCH] Bug 22445: Add new pattern %normalized_isbn% Quite bad to use C4::Koha from Koha::Biblio :-/ Sponsored-by: Orex Digital Signed-off-by: Hayley Mapley Signed-off-by: Hugo Agud Signed-off-by: Owen Leonard Signed-off-by: Michal Denar Signed-off-by: Kyle Hall Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- Koha/Biblio.pm | 5 +++++ .../en/modules/admin/preferences/enhanced_content.pref | 2 +- t/db_dependent/Koha/Biblios.t | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 625352f135..4bf153ae6f 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -24,6 +24,7 @@ use List::MoreUtils qw(any); use URI; use URI::Escape; +use C4::Koha; use C4::Biblio qw(); use Koha::Database; @@ -675,6 +676,10 @@ sub custom_cover_image_url { my $isbn = $self->biblioitem->isbn; $url =~ s|%isbn%|$isbn|g; } + if ( $url =~ m|%normalized_isbn%| ) { + my $normalized_isbn = C4::Koha::GetNormalizedISBN($self->biblioitem->isbn); + $url =~ s|%normalized_isbn%|$normalized_isbn|g; + } if ( $url =~ m|%issn%| ) { my $issn = $self->biblioitem->issn; $url =~ s|%issn%|$issn|g; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref index 1315dd9c03..099b8eb3fe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref @@ -346,7 +346,7 @@ Enhanced Content: - "Using the following URL:" - pref: CustomCoverImagesURL class: url - - "You can defined it using the following patterns: %isbn%, %issn%." + - "You can define it using the following patterns: %isbn%, %issn%, %normalized_isbn%." HTML5 Media: - - Show a tab with a HTML5 media player for files catalogued in field 856 diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t index 2e7ce189e2..177eda81e8 100644 --- a/t/db_dependent/Koha/Biblios.t +++ b/t/db_dependent/Koha/Biblios.t @@ -188,11 +188,11 @@ subtest 'can_be_transferred' => sub { }; subtest 'custom_cover_image_url' => sub { - plan tests => 2; + plan tests => 3; t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/%isbn%_%issn%.png' ); - my $isbn = 'my_isbn'; + my $isbn = '0553573403 | 9780553573404 (pbk.).png'; my $issn = 'my_issn'; my $marc_record = MARC::Record->new; my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, ''); @@ -208,6 +208,10 @@ subtest 'custom_cover_image_url' => sub { t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/%024$a%.png' ); is( $biblio->custom_cover_image_url, "https://my_url/$marc_024a.png" ); + + t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/%normalized_isbn%.png' ); + my $normalized_isbn = C4::Koha::GetNormalizedISBN($isbn); + is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png" ); }; $schema->storage->txn_rollback; -- 2.39.5