From 3f2c17857d497ecad11ce3d871ef0cf86272c9df Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 19 Aug 2021 09:52:14 +0000 Subject: [PATCH] Bug 27461: Move hardcoded value to module Signed-off-by: Marcel de Rooy Signed-off-by: Phil Ringnalda Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Util/FrameworkPlugin.pm | 22 ++++++++++++++- cataloguing/value_builder/marc21_field_008.pl | 28 ++++--------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Koha/Util/FrameworkPlugin.pm b/Koha/Util/FrameworkPlugin.pm index d3fcbb9ac8..bc2c8dabd5 100644 --- a/Koha/Util/FrameworkPlugin.pm +++ b/Koha/Util/FrameworkPlugin.pm @@ -22,11 +22,13 @@ package Koha::Util::FrameworkPlugin; use Modern::Perl; +use constant DEFAULT_008_POS_6_39 => 'b |||||||| |||| 00| 0 eng d'; + our ( @ISA, @EXPORT_OK ); BEGIN { require Exporter; @ISA = qw( Exporter ); - @EXPORT_OK = qw( wrapper date_entered ); + @EXPORT_OK = qw( wrapper date_entered biblio_008 ); } =head1 NAME @@ -65,4 +67,22 @@ sub date_entered { return substr($year,2,2).sprintf ("%0.2d", $mon).sprintf ("%0.2d",$mday); } +=head2 biblio_008 + + Returns a default value for MARC21 field 008 for biblio records. + Depends on prefs DefaultCountryField008, DefaultLanguageField008. + +=cut + +sub biblio_008 { + my $result = date_entered() . DEFAULT_008_POS_6_39; + if( C4::Context->preference('DefaultCountryField008') ) { + substr( $result, 15, 3 ) = pack( "A3", C4::Context->preference('DefaultCountryField008') ); + } + if( C4::Context->preference('DefaultLanguageField008') ) { + substr( $result, 35, 3 ) = pack( "A3", C4::Context->preference('DefaultLanguageField008' ) ); + } + return $result; +} + 1; diff --git a/cataloguing/value_builder/marc21_field_008.pl b/cataloguing/value_builder/marc21_field_008.pl index 9f87ae393b..060715afcf 100755 --- a/cataloguing/value_builder/marc21_field_008.pl +++ b/cataloguing/value_builder/marc21_field_008.pl @@ -28,29 +28,20 @@ use C4::Search; use C4::Output qw( output_html_with_http_headers ); use XML::LibXML; -use Koha::Util::FrameworkPlugin qw|date_entered|; +use Koha::Util::FrameworkPlugin qw( biblio_008 ); my $builder = sub { my ( $params ) = @_; - my $lang = C4::Context->preference('DefaultLanguageField008' ); - $lang = "eng" unless $lang; - $lang = pack("A3", $lang); - my $country = C4::Context->preference('DefaultCountryField008'); - $country = "|||" unless $country; - $country = pack("A3", $country); - my $function_name = $params->{id}; - my $dateentered = date_entered(); + my $default008 = biblio_008(); my $res = "