From 13697a2a954c4128dc3a7ba455bf05dcf973b667 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Wed, 24 Sep 2025 14:44:08 +0200 Subject: [PATCH] Bug 40869: Preserve mandatory fields even if hidden when duplicating item Preserve mandatory fields while when duplicating an item, also when they are non visible. To test: 1) Go to MARC bibliographic framwork and view the marc structure for some framework. 2) Select edit subfield b for tag 952 and make it non visible 3) Go to a biblio using the framework above and edit an item. In the "actions" dropdown, choose to duplicate an item. 4) Now go to the detail page for the biblio, "Current library" should be empty and it should produce a 500 error. 5) Apply patch. 6) Perform steps 3-4 for some other biblio using the same framework. 7) The "Current library" should now be set to the same value as the source item, and no crash should occur. Sponsored-by: Gothenburg University Library --- Koha/UI/Form/Builder/Item.pm | 27 ++++++++++++++------------- cataloguing/additem.pl | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm index c43483895df..a23ccb335ee 100644 --- a/Koha/UI/Form/Builder/Item.pm +++ b/Koha/UI/Form/Builder/Item.pm @@ -452,7 +452,7 @@ Limit info depending on the library (so far only item types). Flag to add an empty option to the library list. -=item ignore_invisible_subfields +=item ignore_non_mandatory_invisible_subfields Skip the subfields that are not visible on the editor. @@ -465,16 +465,16 @@ When duplicating an item we do not want to retrieve the subfields that are hidde sub edit_form { my ( $self, $params ) = @_; - my $branchcode = $params->{branchcode}; - my $restricted_edition = $params->{restricted_editition}; - my $subfields_to_prefill = $params->{subfields_to_prefill} || []; - my $subfields_to_allow = $params->{subfields_to_allow} || []; - my $ignore_not_allowed_subfields = $params->{ignore_not_allowed_subfields}; - my $kohafields_to_ignore = $params->{kohafields_to_ignore} || []; - my $prefill_with_default_values = $params->{prefill_with_default_values}; - my $branch_limit = $params->{branch_limit}; - my $default_branches_empty = $params->{default_branches_empty}; - my $ignore_invisible_subfields = $params->{ignore_invisible_subfields} || 0; + my $branchcode = $params->{branchcode}; + my $restricted_edition = $params->{restricted_editition}; + my $subfields_to_prefill = $params->{subfields_to_prefill} || []; + my $subfields_to_allow = $params->{subfields_to_allow} || []; + my $ignore_not_allowed_subfields = $params->{ignore_not_allowed_subfields}; + my $kohafields_to_ignore = $params->{kohafields_to_ignore} || []; + my $prefill_with_default_values = $params->{prefill_with_default_values}; + my $branch_limit = $params->{branch_limit}; + my $default_branches_empty = $params->{default_branches_empty}; + my $ignore_non_mandatory_invisible_subfields = $params->{ignore_invisible_subfields} || 0; my $libraries = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; @@ -508,8 +508,9 @@ sub edit_form { if grep { $subfield->{kohafield} && $subfield->{kohafield} eq $_ } @$kohafields_to_ignore; next - if $ignore_invisible_subfields - && ( $subfield->{hidden} > 4 || $subfield->{hidden} <= -4 ); + if $ignore_non_mandatory_invisible_subfields + && ( $subfield->{hidden} > 4 || $subfield->{hidden} <= -4 ) + && !$subfield->{mandatory}; my $readonly; if ( @$subfields_to_allow diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 5c3e2005124..a64f9b9b6fc 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -790,7 +790,7 @@ my $subfields = branch_limit => C4::Context->userenv->{"branch"}, ( $op eq 'dupeitem' - ? ( ignore_invisible_subfields => 1 ) + ? ( ignore_non_mandatory_invisible_subfields => 1 ) : () ), } -- 2.49.0