From 207b53940674540f2e860a7488f1bf4ead6f12dd 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 (cherry picked from commit 24d2e08c94ed6e25d7666d6fe2ae342645eb9232) Signed-off-by: Fridolin Somers --- 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 9b29287c76..7723746395 100644 --- a/Koha/Util/FrameworkPlugin.pm +++ b/Koha/Util/FrameworkPlugin.pm @@ -22,12 +22,14 @@ package Koha::Util::FrameworkPlugin; use Modern::Perl; +use constant DEFAULT_008_POS_6_39 => 'b |||||||| |||| 00| 0 eng d'; + our ( @ISA, @EXPORT, @EXPORT_OK ); BEGIN { require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( ); - @EXPORT_OK = qw( wrapper date_entered ); + @EXPORT_OK = qw( wrapper date_entered biblio_008 ); } =head1 NAME @@ -66,4 +68,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 0951e10a6a..c9d6631465 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; 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 = "