Multiple value entity reference field broken

Created on 16 July 2024, 4 months ago
Updated 2 August 2024, 4 months ago

Problem/Motivation

I'm trying to use Transform API with Paragraphs, but this seems to happen with any entity reference (revisions) field. Essentially any reference fields with cardinality > 1 are buggy.

On a node, I have an 'Elements' field that references Paragraphs. The referenced Paragraph type has a text field, which is set visible in Transform Mode setting for the Paragraph.

When set as a single value field in field settings, JSON gets populated correctly with the text field value as expected, no issues.

But when the cardinality is set to unlimited, I run into issues.

1. When I empty the cache and load the JSON page, entity reference field values do not include the text field, but are otherwise ok.

2. When I save the node and again open the JSON page, every element instance on all nodes for the same field get populated with the same globally last added item (id is the same for all, and the text field is included).

Emptying the cache again restores the state where the Paragraph instances exist in JSON with their proper ids, but the text field is missing.

3. When I leave any entity reference (revisions) field empty, save the node, I get the following error instead of the JSON:

The website encountered an unexpected error. Try again later.<br><br><em class="placeholder">TypeError</em>: Drupal\transform_api\Transform\EntityTransform::getEntity(): Return value must be of type Drupal\Core\Entity\EntityInterface, false returned in <em class="placeholder">Drupal\transform_api\Transform\EntityTransform-&gt;getEntity()</em> (line <em class="placeholder">115</em> of <em class="placeholder">modules/contrib/transform_api/src/Transform/EntityTransform.php</em>). <pre class="backtrace">Drupal\transform_api\Transform\EntityTransform-&gt;getTransformBuilder() (Line: 220)
Drupal\transform_api\Transform\EntityTransform-&gt;transform() (Line: 153)
Drupal\transform_api\Plugin\Transform\Field\EntityTransform-&gt;transformElements() (Line: 108)
Drupal\transform_api\FieldTransformBase-&gt;transform() (Line: 290)
Drupal\transform_api\Entity\EntityTransformDisplay-&gt;buildMultiple() (Line: 388)
Drupal\transform_api\Entity\EntityTransformBuilder-&gt;buildComponents() (Line: 324)
Drupal\transform_api\Entity\EntityTransformBuilder-&gt;buildMultiple() (Line: 276)
Drupal\transform_api\Entity\EntityTransformBuilder-&gt;build()

My nodes are translatable, but otherwise the setup is very basic. Transform Modes on node type and Paragraphs are configured to show the fields.

🐛 Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

🇫🇮Finland irowboat

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

Comments & Activities

Production build 0.71.5 2024