From 48ecfb0d9bbd24c7d750d149c6ecd1a8be850ac8 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Fri, 4 Apr 2025 09:04:50 +0000 Subject: [PATCH] Bug 39560: For authorities, hidded fields (but present in the record) will be lost when editing and saving such a record If a subfield is present in the authority record, but this subfield is marked as 'Hide all', then if you edit and save such a record, the data from hidden fields wil be lost forever. This behavior differs from bibliographic records editor, when even if a subfield is hidden (not active) in the editor it will be activated and present in the editor if present in the record. The problem affect above all records imported from external agencies. Test plan: ========== 1. Have any authority record. Note one present subfield (e.g. 100 $d). 2. Modify the record framework for this type of record (/cgi-bin/koha/admin/authtypes.pl), marking the subfield 'Hide all'. 3. Open the record in the editor and save. 4. Re-enable the subfield in the framework, marking it as 'Show all' now. 5. Reopen the record in the editor. Note that the previous content of the subfield you played with is gone. Enter any new value and save. 6. Apply the patch ; restart all. 7. Repeat p. 2, i.e. hide the subfield again. Open the record in the editor. You should see the content of the hidden field as you would for a bibliographic record with a subfield hidden in the editor but present in a record. (Note also that the content of this subfield is visible in record view). 8. Open the editor with an empty record (New authority) of the type in question. Control that the subfield is hidden (not accessible) for a new record. BTW Note that the "hidden" but present subfields are visible in OPAC, but not in the staff interface *before* applying the patch. The patch changes nothing for OPAC. Signed-off-by: Magnus Enger --- authorities/authorities.pl | 9 ++++++--- authorities/detail.pl | 3 --- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 3385a260fa..f66c13605d 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -160,7 +160,7 @@ sub create_input { } $subfield_data{visibility} = "display:none;" - if ( $tagslib->{$tag}->{$subfield}->{hidden} and $value ne '' + if ( $tagslib->{$tag}->{$subfield}->{hidden} and $value eq '' or ( $value eq '' and !$tagslib->{$tag}->{$subfield}->{mandatory} ) ); # it's an authorised field @@ -380,7 +380,7 @@ sub build_tabs { $subfield = '@'; } next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop ); - next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9'; + next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9' && !$value; push( @subfields_data, &create_input( @@ -395,7 +395,10 @@ sub build_tabs { my $value = $subfields[$subfieldcount][1]; next if ( length $subfield != 1 ); next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop ); - next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9'; + next + if $tagslib->{$tag}->{$subfield}->{hidden} + && $subfield ne '9' + && ( !$value || $tag eq '942' ); push( @subfields_data, &create_input( diff --git a/authorities/detail.pl b/authorities/detail.pl index dbe42f1bc4..595a357a9e 100755 --- a/authorities/detail.pl +++ b/authorities/detail.pl @@ -99,7 +99,6 @@ sub build_tabs { if ( $field->tag() < 10 ) { next if ( $tagslib->{ $field->tag() }->{'@'}->{tab} ne $tabloop ); - next if ( $tagslib->{ $field->tag() }->{'@'}->{hidden} ); my %subfield_data; $subfield_data{marc_lib} = $tagslib->{ $field->tag() }->{'@'}->{lib}; $subfield_data{marc_value} = $field->data(); @@ -114,8 +113,6 @@ sub build_tabs { $subf[$i][0] = "@" unless defined $subf[$i][0]; next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne $tabloop ); - next - if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} ); my %subfield_data; $subfield_data{marc_lib} = $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib}; if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl} ) { -- 2.34.1