[Koha-bugs] [Bug 26635] Expand authorised values in REST API call

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Mon Apr 5 12:44:49 CEST 2021


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=26635

--- Comment #23 from Agustín Moyano <agustinmoyano at theke.io> ---
(In reply to Martin Renvoize from comment #22)
> (In reply to Tomás Cohen Arazi from comment #21)
> > (In reply to Tomás Cohen Arazi from comment #18)
> > > (In reply to Martin Renvoize from comment #17)
> > > > I'm not sure we need the full AV object expanded.. and I'm thinking if would
> > > > be 'nicer' to access it directly rather than have to do a subsequent lookup
> > > > in JS?
> > > 
> > > I would go for an $av->to_api object, that names things better: lib/lib_opac
> > > => description, picking the right one according to the caller context.
> > 
> > What do you think, Agustín?
> 
> I'm onboard with this... embedding them and using to_api to make the naming
> clear.. I reckon we could be onto a winner

Now it is actually doing a "to_api" on avs when it does:


+        $avs = $self->_do_api_mapping($avs);

and then

+sub _do_api_mapping {
+    my ($self, $json_object) = @_;
+    # Rename attributes if there's a mapping
+    if ( $self->can('to_api_mapping') ) {
+        foreach my $column ( keys %{ $self->to_api_mapping } ) {
+            my $mapped_column = $self->to_api_mapping->{$column};
+            if ( exists $json_object->{$column}
+                && defined $mapped_column )
+            {
+                # key != undef
+                $json_object->{$mapped_column} = delete
$json_object->{$column};
+            }
+            elsif ( exists $json_object->{$column}
+                && !defined $mapped_column )
+            {
+                # key == undef
+                delete $json_object->{$column};
+            }
+        }
+    }
     return $json_object;
 }

what we are currently lacking is "to_api_mapping" in AuthorisedValues

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list