next unless $tag;
next if $tag == $itemfield;
for my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
- next unless ref $tagslib->{$tag}{$subfield}; # Not a valid subfield (mandatory, tab, lib)
+ next if IsMarcStructureInternal($tagslib->{$tag}{$subfield});
my $defaultvalue = $tagslib->{$tag}{$subfield}{defaultvalue};
if ( defined $defaultvalue and $defaultvalue ne '' ) {
my @fields = $record->field($tag);
&GetAuthorisedValueDesc
&GetMarcStructure
+ &IsMarcStructureInternal
&GetMarcFromKohaField
&GetMarcSubfieldStructureFromKohaField
&GetFrameworkCode
=head1 FUNCTIONS FOR HANDLING MARC MANAGEMENT
+=head2 IsMarcStructureInternal
+
+ my $tagslib = C4::Biblio::GetMarcStructure();
+ for my $tag ( sort keys %$tagslib ) {
+ next unless $tag;
+ for my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
+ next if IsMarcStructureInternal($tagslib->{$tag}{$subfield});
+ }
+ # Process subfield
+ }
+
+GetMarcStructure creates keys (lib, tab, mandatory, repeatable) for a display purpose.
+These different values should not be processed as valid subfields.
+
+=cut
+
+sub IsMarcStructureInternal {
+ my ( $subfield ) = @_;
+ return ref $subfield ? 0 : 1;
+}
+
=head2 GetMarcStructure
$res = GetMarcStructure($forlibrarian,$frameworkcode);
# loop through each subfield
my $cntsubf;
foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
- next unless ref $tagslib->{$tag}{$subfield}; # Not a valid subfield (mandatory, tab, lib)
+ next if IsMarcStructureInternal($tagslib->{$tag}{$subfield});
next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
my %subfield_data;
$subfield_data{tag} = $tag;
# We generate form, and fill with values if defined
foreach my $tag ( keys %{$tagslib}){
foreach my $subtag (keys %{$tagslib->{$tag}}){
- next unless ref $tagslib->{$tag}{$subtag}; # Not a valid subfield (mandatory, tab, lib)
+ next if IsMarcStructureInternal($tagslib->{$tag}{$subtag});
next if ($tagslib->{$tag}->{$subtag}->{'tab'} ne "10");
next if any { /^$tag$subtag$/ } @fields;
use Modern::Perl;
-use Test::More tests => 5;
+use Test::More tests => 6;
use Test::MockModule;
+use List::MoreUtils qw( uniq );
use MARC::Record;
use t::lib::Mocks qw( mock_preference );
is($marc_subfield_structure, undef, "invalid kohafield returns undef");
};
+subtest 'IsMarcStructureInternal' => sub {
+ plan tests => 6;
+ my $tagslib = GetMarcStructure();
+ my @internals;
+ for my $tag ( sort keys %$tagslib ) {
+ next unless $tag;
+ for my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
+ push @internals, $subfield if IsMarcStructureInternal($tagslib->{$tag}{$subfield});
+ }
+ }
+ @internals = uniq @internals;
+ is( scalar(@internals), 4, '');
+ is( grep( /^lib$/, @internals ), 1, '' );
+ is( grep( /^tab$/, @internals ), 1, '' );
+ is( grep( /^mandatory$/, @internals ), 1, '' );
+ is( grep( /^repeatable$/, @internals ), 1, '' );
+ is( grep( /^a$/, @internals ), 0, '' );
+};
+
1;
foreach my $tag (sort keys %{$tagslib}) {
# loop through each subfield
foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
- next unless ref $tagslib->{$tag}{$subfield}; # Not a valid subfield (mandatory, tab, lib)
+ next if IsMarcStructureInternal( $tagslib->{$tag}{$subfield} );
next if (not $allowAllSubfields and $restrictededition && !grep { $tag . '$' . $subfield eq $_ } @subfieldsToAllow );
next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
# barcode and stocknumber are not meant to be batch-modified