From e45a836df3367e94c3c3f4c8e253252faa3eff8a Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Thu, 16 Mar 2023 10:24:42 +0100 Subject: [PATCH] Bug 32748: Prevent data erasing when editing item When we set an authorised value linked to one library, users who do not belong to this library do not get the value and can therefore overwrite it. This patch add current value to the dropdown list even if it comes from an authorized value of another library. Test plan : 1) Edit an item with one of these fields has an authorized value from another library. 2) See that you don't get this value on 'edit' 3) Apply this patch 4) Refresh and do step 1 5) Now you have the value in dropdown list --- Koha/UI/Form/Builder/Item.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm index 3a478ee05e..6ea855394e 100644 --- a/Koha/UI/Form/Builder/Item.pm +++ b/Koha/UI/Form/Builder/Item.pm @@ -252,10 +252,20 @@ sub generate_subfield_form { else { push @authorised_values, qq{}; my $av = GetAuthorisedValues( $subfield->{authorised_value} ); + my $current_value_av = Koha::AuthorisedValues->search({ authorised_value => $value })->next; + for my $r (@$av) { push @authorised_values, $r->{authorised_value}; $authorised_lib{ $r->{authorised_value} } = $r->{lib}; } + if ( defined $current_value_av ) { + my $current_av_code = $current_value_av->authorised_value; + my $current_av_lib = $current_value_av->lib; + if ( !grep { $_ eq $current_av_code } @authorised_values ) { + push @authorised_values, $current_av_code; + $authorised_lib{$current_av_code} = $current_av_lib; + } + } } if ( $subfield->{hidden} > 4 or $subfield->{hidden} <= -4 ) { @@ -572,7 +582,7 @@ sub edit_form { prefill_with_default_values => $prefill_with_default_values, branch_limit => $branch_limit, default_branches_empty => $default_branches_empty, - readonly => $readonly + readonly => $readonly, } ); push @subfields, $subfield_data; -- 2.25.1