How to use returnScalar option in a theme?

Hi everyone,

In a Omeka S theme, I would like to use the option returnScalar in a API search request. Here is my code:

$options = [];
$item_ids = $this->api()->search('items', $options, ['returnScalar' => 'id'])->getContent();
print_r(json_encode($item_ids));

but the result is not what I expect: instead of an array of IDs, I get an array of item representations.

I wrote the equivalent code in a module, and the result is indeed an array of IDs. The code in the module:

$options = [];
$item_ids = $api->search('items', $options, ['returnScalar' => 'id'])->getContent();
$logger->notice($item_ids);

How can I get an array of IDs with returnScalar in a theme?

Vincent

Your problem here is that the API theme helper doesn’t have that third argument to set the options. What you’re passing there just gets ignored.

The options like returnScalar were always more envisioned as for use by modules or the core… I don’t think there’s an issue with exposing them to the theme through the helper, though. But it’s something we’d have to do in a future release.

Thanks for your reply, John. I’ll go through the module in that case.
I think it would indeed be interesting if returnScalar could be used in a theme.

We’re going to go ahead and make the change to allow options there.

1 Like