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\ReferenceFieldPropExpressionallows 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().
Issue fork experience_builder-3543358
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
wim leersThis is the original bug, but would be great to actually test it for
ReferenceFieldPropExpressionandReferenceFieldTypePropExpressiontoo!Comment #4
wim leersComment #5
phenaproximaComment #6
wim leersComment #7
wim leersYay for unit tests and the absence of layers of indirection (such as these prop expressions being defined by plugin types). This is the most tightly scoped MR I've seen in a while 🕺