Disabled resources vs. includes (for referenced data)

Created on 3 April 2024, 3 months ago

Problem/Motivation

In larger Drupal projects with many entities and entity types it becomes more and more unlikely that you want to expose all existing resources, so the Disabled by default ("If activated, all resource types that don't have a matching enabled resource config will be disabled.") is very helpful.

But as I had to find out after confusion, this also has the effect that referenced entities data (values) is no more directly exposable by using includes or field enhancers. They just don't return results any more. Also https://www.drupal.org/project/jsonapi_include β†’ doesn't provide any data.

Steps to reproduce

You have a node type with a media image referenced and simply want to retrieve the image uri and the image alt text via API, just like other field values from this entity type, e.g. expected result (see the field_image example, which is node > media > file > data)

"attributes": {
  "drupal_internal__nid": 298662,
  "drupal_internal__vid": 306330,
  "langcode": "de",
  "status": true,
  "title": "My example content with a media image field",
  "created": "2024-03-27T14:11:04+00:00",
  "changed": "2024-03-27T14:11:04+00:00",
  "field_image": {
    "uri": "xyz",
    "alt": "Lorem ipsum"
  }, [...]

Proposed resolution

  • Add further information to the "Disabled by default"-switch to explain that references are also affected server-side, until this is solved
  • Allow including reference fields data server-side (e.g. by field enhancer) by adding an option for this on the field resource (even if the target type is disabled)
  • Allow including reference fields data server-side via ?includes parameter by adding an option for this on the field resource (even if the target type is disabled)

I think the field enhancer, if selected, could just ignore the disabled status of the reference target, while allowing to use it as include should definitely be a checkbox option to opt-into.

To have at least one of these options to access the reference data without the need to enable all these target resources for the client would be super helpful!

Remaining tasks

[ ] Discuss
[ ] Implement
[ ] Test
[ ] Release

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024