@@ -, +, @@ create a subfield that is not linked to a DB column. Save even if you made no changes to make sure that marc_subfield_structure.kohafield is set to an empty string. I'll use 995$Z as an example for the following steps. #995|
Item:|{995Z}| value you entered in 995$Z is not visible --- Koha/Item.pm | 2 +- t/db_dependent/Koha/Item.t | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) --- a/Koha/Item.pm +++ a/Koha/Item.pm @@ -957,7 +957,7 @@ sub as_marc_field { my $kohafield = $subfield->{kohafield}; my $tagsubfield = $subfield->{tagsubfield}; my $value; - if ( defined $kohafield ) { + if ( defined $kohafield && $kohafield ne '' ) { next if $kohafield !~ m{^items\.}; # That would be weird! ( my $attribute = $kohafield ) =~ s|^items\.||; $value = $self->$attribute # This call may fail if a kohafield is not a DB column but we don't want to add extra work for that there --- a/t/db_dependent/Koha/Item.t +++ a/t/db_dependent/Koha/Item.t @@ -310,7 +310,7 @@ subtest "as_marc_field() tests" => sub { my @schema_columns = $schema->resultset('Item')->result_source->columns; my @mapped_columns = grep { exists $mss->{'items.'.$_} } @schema_columns; - plan tests => 2 * (scalar @mapped_columns + 1) + 3; + plan tests => 2 * (scalar @mapped_columns + 1) + 4; $schema->storage->txn_begin; @@ -355,9 +355,17 @@ subtest "as_marc_field() tests" => sub { tagsubfield => 'X', } )->store; + Koha::MarcSubfieldStructure->new( + { + frameworkcode => '', + tagfield => $itemtag, + tagsubfield => 'Y', + kohafield => '', + } + )->store; my @unlinked_subfields; - push @unlinked_subfields, X => 'Something weird'; + push @unlinked_subfields, X => 'Something weird', Y => 'Something else'; $item->more_subfields_xml( C4::Items::_get_unlinked_subfields_xml( \@unlinked_subfields ) )->store; Koha::Caches->get_instance->clear_from_cache( "MarcStructure-1-" ); @@ -377,7 +385,8 @@ subtest "as_marc_field() tests" => sub { } @subfields; is_deeply(\@subfields, \@ordered_subfields); - is( scalar $marc_field->subfield('X'), 'Something weird', 'more_subfield_xml is considered' ); + is( scalar $marc_field->subfield('X'), 'Something weird', 'more_subfield_xml is considered when kohafield is NULL' ); + is( scalar $marc_field->subfield('Y'), 'Something else', 'more_subfield_xml is considered when kohafield = ""' ); $schema->storage->txn_rollback; Koha::Caches->get_instance->clear_from_cache( "MarcStructure-1-" ); --