I'm now working on a custom listing view. I'm trying to figure out the pattern for providing additional fields to listing items.
Out of the box, Volto retrieves listings that return @id, @type, description, title and url
Like this:
{
@id: "http://localhost:3000/myfolder",
@type: "folder",
description: "This is my folder",
review_state: "open",
title: "My folder",
url: "/myfolder",
}
I'd like to also return the tags associated with each listing item.
So something like this:
{
@id: "http://localhost:3000/myfolder",
@type: "folder",
description: "This is my folder",
review_state: "open",
title: "My folder",
url: "/myfolder",
tags: ["interesting","stimulating","last one"]
}
I feel there's a nicer way* to do this but this way is documented and I know it will work.
The searchContent helper provides a way to send a custom query to the api. More important is the ability to request the fullobjects when doing the query, so I'll get my tags.
Thanks @tiberiuichim so either (1) use the searchContent helper or (2) solve it on the backend with the 'JSONSummarySerializerMetadata'. If we're playing to the skills of a frontend developer then (1) is the better option.
Avoiding full_objects is better, though. Reducing the problem, we're basically talking about "waking zodb objects for listing vs just reading their metadata from the catalog", but it goes even further: content serialization can get quite large (it includes the blocks, information about children, etc) and that type of info gets repeated across all the items in the listing.
Yes, indeed, it's not in the reach of frontend developers (although I have a colleague who started as a frontend dev exclusively with React and now he's all over, poking through the backend stack).
On the other hand, outside Volto, we didn't really have a "frontend stack only" developer role with Plone.
@tiberiuichim Is it possible to simply overwrite the summary.py and thus expand the list of fields in JSONSummarySerializerMetadata? I found a dark hint that you should create an overrides folder in your addon and save a summary.py with changed content there, but unfortunately this has no effect
Hmm, I have now activated a RichText field as a behavior in the content-type News Item. This field is simply called "text" . If I try to enter this field in default_metadata_fields of the JSONSummarySerializerMetadata class in order to be able to see the field in the listing (summary), the following error occurs
test-backend-1 | Module plone.restapi.serializer.converters, line 80, in default_converter
test-backend-1 | TypeError: No converter for making RichTextValue object. (Did you mean <attribute>.raw or <attribute>.output?) (<class 'plone.app.textfield.value.RichTextValue'>) JSON compatible.
If I now set a field_accessors for text based on the example from summary.py, the error in the listing is gone.