Cannot parse a prop expression that traverses multiple levels of entity references

Created on 27 August 2025, 1 day ago

Overview

I've been building some content templates, by hand, for Drupal CMS. We need to be able to return image shapes to SDC props, like {image_url, alt}, from a normal two-level media reference field on a node.

You would think a prop expression like this would do the trick (assuming that yo_ho is a normal media reference field):

'ℹ︎␜entity:node:foo␝yo_ho␞␟{src↝entity␜␜entity:media:image␝field_media_image␞␟entity␜␜entity:file␝uri␞␟url,alt↝entity␜␜entity:media:image␝field_media_image␞␟alt}'

But you'd be wrong, because there is a bug in FieldObjectPropsExpression::fromString(). The nature of the bug, according to Wim in Slack:

  • \Drupal\experience_builder\PropExpressions\StructuredData\ReferenceFieldPropExpression allows chaining of references: public readonly ReferenceFieldPropExpression|FieldPropExpression|FieldObjectPropsExpression $referenced
  • BUT FieldObjectPropsExpression::fromString()’s logic does not yet do that:
            $objectPropsToFieldTypeProps[$sdc_obj_prop_name] = new ReferenceFieldPropExpression(
              new FieldPropExpression($entity_data_definition, $field_name, NULL, $field_instance_prop_name),
              FieldPropExpression::fromString(self::PREFIX . $field_prop_ref_expr)
            );
    

Proposed resolution

It's a one-line fix. We need to call StructuredDataPropExpression::fromString(), not FieldPropExpression::fromString().

🐛 Bug report
Status

Active

Version

1.0

Component

… to be triaged

Created by

🇺🇸United States phenaproxima Massachusetts

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024