https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=26635 --- Comment #24 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Agustín Moyano from comment #23)
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
Well, we certainly need that, but we also need to call ->to_api instead of the hand-crafted _do_api_mapping(). That's because we could want to call it with { public => 1 } and thus making the av representation dependent on the context. This example snippet from an hypothetical Koha::AuthorisedValue->to_api() might illustrate what I mean: my $json = $self->SUPER::to_api($params); my $description = $json->{description}; $description = $json->{description_opac} if $params->{public} and defined $json->{description_opac} and $json->{description_opac} ne ''; -- You are receiving this mail because: You are watching all bug changes.