Bug 22445: Allow marc fields as pattern
%tag$field% There is a limitation here, only one replacement will work. Let see if it is needed later to support several patterns Sponsored-by: Orex Digital Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz> Signed-off-by: Hugo Agud <hagud@orex.es> Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Michal Denar <black23@gmail.com> Signed-off-by: Kyle Hall <kyle@bywatersolutions.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
3df15701d6
commit
e3b90c4cb9
|
|
@ -679,6 +679,16 @@ sub custom_cover_image_url {
|
|||
my $issn = $self->biblioitem->issn;
|
||||
$url =~ s|%issn%|$issn|g;
|
||||
}
|
||||
|
||||
my $re = qr|%(?<field>\d{3})\$(?<subfield>.)%|;
|
||||
if ( $url =~ $re ) {
|
||||
my $field = $+{field};
|
||||
my $subfield = $+{subfield};
|
||||
my $marc_record = $self->metadata->record;
|
||||
my $value = $marc_record->subfield($field, $subfield);
|
||||
$url =~ s|$re|$value|;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use Modern::Perl;
|
|||
|
||||
use Test::More tests => 6;
|
||||
use Test::Exception;
|
||||
use MARC::Field;
|
||||
|
||||
use C4::Items;
|
||||
use C4::Biblio;
|
||||
|
|
@ -187,18 +188,26 @@ subtest 'can_be_transferred' => sub {
|
|||
};
|
||||
|
||||
subtest 'custom_cover_image_url' => sub {
|
||||
plan tests => 1;
|
||||
plan tests => 2;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/%isbn%_%issn%.png' );
|
||||
|
||||
my $isbn = 'my_isbn';
|
||||
my $issn = 'my_issn';
|
||||
my $biblioitem = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Biblioitems',
|
||||
value => { isbn => $isbn, issn => $issn }
|
||||
}
|
||||
);
|
||||
my $biblio = Koha::Biblios->find( $biblioitem->biblionumber );
|
||||
my $marc_record = MARC::Record->new;
|
||||
my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, '');
|
||||
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $biblioitem = $biblio->biblioitem->set(
|
||||
{ isbn => $isbn, issn => $issn });
|
||||
is( $biblio->custom_cover_image_url, "https://my_url/${isbn}_${issn}.png" );
|
||||
|
||||
my $marc_024a = '710347104926';
|
||||
$marc_record->append_fields( MARC::Field->new( '024', '', '', a => $marc_024a ) );
|
||||
C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/%024$a%.png' );
|
||||
is( $biblio->custom_cover_image_url, "https://my_url/$marc_024a.png" );
|
||||
};
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
Loading…
Reference in New Issue