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

Command icon 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

apmsooner created an issue. See original summary.

apmsooner’s picture

Issue summary: View changes
apmsooner’s picture

StatusFileSize
new92.3 KB
apmsooner’s picture

Issue summary: View changes

apmsooner’s picture

Status: Active » Needs review
StatusFileSize
new812 bytes
apmsooner’s picture

StatusFileSize
new875 bytes

Revising patch to prevent normal route includes from working.

apmsooner’s picture

Issue summary: View changes

albertosilva made their first commit to this issue’s fork.

albertosilva’s picture

Assigned: Unassigned » albertosilva
Status: Needs review » Fixed

HI,

Thanks for your patch, I've already merged it and will publish a new version soon.

albertosilva’s picture

Status: Fixed » Closed (fixed)
apmsooner’s picture

Hey 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