Problem/Motivation
I have a node with multi-valued entity_reference_revisions (paragraphs) field. My node is in create mode and i have 2 paragraph entities as values associated with field machine name field_components. When i add include for field_components, only the last value shows up in the included array.
Steps to reproduce
Add a multi-valued paragraphs field to node. Create a new node with 2 different types of paragraphs selected for the field. View the jsonapi endpoint with include for the field. Notice the attributes value shows multiple but the actual includes only show 1.
Proposed resolution
Refactor line 110 in IncludeResolver.php. Multiple values are present up until this line:
$references[$target_type][$field_item->get($field_item::mainPropertyName())->getValue()] = $in_preview ? $field_item->entity : NULL;
Changing to this works:
$references[$target_type][$field_item->get($field_item::mainPropertyName())->getValue()][] = $in_preview ? $field_item->entity : NULL;
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | refactor-includes-3343283-7.patch | 875 bytes | apmsooner |
| #3 | Screen Shot 2023-02-20 at 7.19.08 PM.png | 92.3 KB | apmsooner |
Issue fork jsonapi_node_preview-3343283
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
apmsooner commentedComment #3
apmsooner commentedComment #4
apmsooner commentedComment #6
apmsooner commentedComment #7
apmsooner commentedRevising patch to prevent normal route includes from working.
Comment #8
apmsooner commentedComment #11
albertosilvaHI,
Thanks for your patch, I've already merged it and will publish a new version soon.
Comment #12
albertosilvaComment #13
apmsooner commentedHey Alberto,
I ended up forking a version of your code as a sub-module into my own as I changed some other logic as well to get it to work the way i needed it to and its been quite a while since i submitted this patch. I've documented your module as an alternative. If you plan to continue supporting yours, be aware you will need to create a new version to support Drupal 10.2 as there are some breaking changes in jsonapi. You can see my latest version for reference:
https://www.drupal.org/project/simple_decoupled_preview