@@ -, +, @@ fields --- Koha/Biblio.pm | 10 ++++++++-- t/db_dependent/Koha/Biblios.t | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) --- a/Koha/Biblio.pm +++ a/Koha/Biblio.pm @@ -772,12 +772,18 @@ sub custom_cover_image_url { $url =~ s|{issn}|$issn|g; } - my $re = qr|{(?\d{3})\$(?.)}|; + my $re = qr|{(?\d{3})(\$(?.))?}|; 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|; } --- a/t/db_dependent/Koha/Biblios.t +++ a/t/db_dependent/Koha/Biblios.t @@ -193,12 +193,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, ''); @@ -221,6 +222,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; --