- Issue created by @jeffschuler
- πΊπΈUnited States jeffschuler Boulder, Colorado
I tried enabling the
test_computed_field_output
module and creating a computed field with each of its plugins. Same problem: they show up in the theme but not in JSON:API output. - π¬π§United Kingdom joachim
That's weird, it should just work -- see π¬ Complete JSON:API's handling of field (including computed & empty fields) cache metadata Needs work , https://gorannikolovski.com/blog/add-computed-field-jsonapi-response
Can you debug?
- πΊπΈUnited States jeffschuler Boulder, Colorado
Thanks @joachim. It does just work in 2.x & 3.x. Both those links you shared would be pre 4.x, no?
I downgraded back to 3.x to keep moving, but will revisit and dig further when time allows.
I could see the field listed in JSON:API Extras β ' Resource overrides pane for my entity (/admin/config/services/jsonapi/resource_types)... so it's being registered in some way.
- π¬π§United Kingdom joachim
> Thanks @joachim. It does just work in 2.x & 3.x. Both those links you shared would be pre 4.x, no?
They are for computed fields in general, independent of this module.
- πΊπΈUnited States daniel korte Brooklyn, NY
Iβm experiencing the same issue. The field shows up everywhere except the JSON output.
- πΊπΈUnited States daniel korte Brooklyn, NY
Okay, it worked for me if I defined my computed field in code only (i.e. not adding the computed field to an entity bundle via the Field UI):
/** * Computed field string. * * @ComputedField( * id = "computed_field_attached", * label = @Translation("Computed field"), * field_type = "string", * no_ui = TRUE, * attach = { * "scope" = "base", * "field_name" = "computed_field", * "entity_types" = { * "node" = { * "article", * }, * }, * }, * ) */
- π¬π§United Kingdom joachim
In that case, it it looks like this is a base field / bundle field problem.
- π¨π¦Canada lambic
I'm seeing the field in my jsonapi output, but it's only showing the first value. My computeValue method returns [1,2] but in the jsonapi I just see "1"