Bug 29172: Make CustomCoverImagesURL compatible with control fields
Bug 22445 added CustomCoverImagesURL that deals with MARC fields, but
control fields were not supported.
Test plan:
Turn CustomCoverImages on
Fill CustomCoverImagesURL with https://covers.openlibrary.org/b/isbn/{006}-M.jpg
Add an isbn in 006 (0596001738 will work)
Go to the detail page of the bibliographic record and confirm that you
see a cover image.
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit 931ef856f9)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
35f6aafc3a
commit
7c77b7c95f
|
|
@ -770,12 +770,18 @@ sub custom_cover_image_url {
|
|||
$url =~ s|{issn}|$issn|g;
|
||||
}
|
||||
|
||||
my $re = qr|{(?<field>\d{3})\$(?<subfield>.)}|;
|
||||
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);
|
||||
my $value;
|
||||
if ( $subfield ) {
|
||||
$value = $marc_record->subfield( $field, $subfield );
|
||||
} else {
|
||||
my $controlfield = $marc_record->field($field);
|
||||
$value = $controlfield->data() if $controlfield;
|
||||
}
|
||||
return unless $value;
|
||||
$url =~ s|$re|$value|;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,12 +189,13 @@ subtest 'can_be_transferred' => sub {
|
|||
};
|
||||
|
||||
subtest 'custom_cover_image_url' => sub {
|
||||
plan tests => 4;
|
||||
plan tests => 6;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' );
|
||||
|
||||
my $isbn = '0553573403 | 9780553573404 (pbk.).png';
|
||||
my $issn = 'my_issn';
|
||||
my $cf_value = 'from_control_field';
|
||||
my $marc_record = MARC::Record->new;
|
||||
my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, '');
|
||||
|
||||
|
|
@ -217,6 +218,12 @@ subtest 'custom_cover_image_url' => sub {
|
|||
$biblio->biblioitem->isbn('')->store;
|
||||
is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{001}.png' );
|
||||
is( $biblio->custom_cover_image_url, undef, 'Record does not have 001' );
|
||||
$marc_record->append_fields(MARC::Field->new('001', $cf_value));
|
||||
C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber );
|
||||
$biblio = Koha::Biblios->find( $biblionumber );
|
||||
is( $biblio->get_from_storage->custom_cover_image_url, "https://my_url/$cf_value.png", 'URL generated using 001' );
|
||||
};
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
Loading…
Reference in New Issue