Bug 9156: itemcallnumber not pulling more than 2 subfields

When the itemcallnumber system preference is defined, the item add form
pulls data from the specified tag and subfield(s) to pre-populate the
call number field. This update makes it possible to build the
prepopulated callnumber from more than just the first two subfields.

To test, apply the patch and update the itemcallnumber system preference
so that it includes more than two subfields. For instance, "092abef"

 - Edit a bibliographic record and populate the specified subfields.
   e.g. subfield a -> "One", b-> "Two", e-> "Three", f-> "Four".
 - Save the record and go to the add/edit items screen.
 - The call number field should contain a string which contains each of
   the subfields you populated, concatenated with spaces: "One Two Three
   Four."
 - Test with other numbers of subfields.
 - Test with an empty itemcallnumber preference.

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Owen Leonard 2019-11-19 14:56:05 +00:00 committed by Martin Renvoize
parent 8c6cb79f66
commit da2f9e7500
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -154,17 +154,23 @@ sub generate_subfield_form {
my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
if (!$value && $subfieldlib->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
my $CNtag = substr($pref_itemcallnumber, 0, 3);
my $CNsubfield = substr($pref_itemcallnumber, 3, 1);
my $CNsubfield2 = substr($pref_itemcallnumber, 4, 1);
my $CNtag = substr( $pref_itemcallnumber, 0, 3 ); # 3-digit tag number
my $CNsubfields = substr( $pref_itemcallnumber, 3 ); # Any and all subfields
my @subfields = ( $CNsubfields =~ m/./g ); # Split into single-character elements
my $temp2 = $temp->field($CNtag);
if ($temp2) {
$value = join ' ', $temp2->subfield($CNsubfield) || q{}, $temp2->subfield($CNsubfield2) || q{};
my @selectedsubfields;
foreach my $subfieldcode( @subfields ){
push @selectedsubfields, $temp2->subfield( $subfieldcode );
}
$value = join( ' ', @selectedsubfields );
#remove any trailing space incase one subfield is used
$value =~ s/^\s+|\s+$//g;
}
}
if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){
my $input = new CGI;
$value = $input->param('barcode');