Explicit test coverage for label generation of suggested optional multi-bundle reference field `DynamicPropSource`s
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3557029. --> Reported by: [mglaman](https://www.drupal.org/user/2416470) Related to !306 >>> <h3 id="overview">Overview</h3> <p>Encountered this when working with Acquia DAM and Content Templates. There was a field on the Article content type that referenced Acquia DAM media types and the normal image/video media types. Canvas was failing over the bundle fields on the Acquia DAM media types. I feel like there may be another way to reproduce, but this was how we triggered.</p> <p>When loading a form for a component a 500 error was returned:</p> <pre>Error 500: Field acquia_dam_alt_text does not exist on entity:media:acquia_dam_image_asset entities.</pre><p>But the field definitely exists in the bundle's field definitions. In <code>\Drupal\canvas\ShapeMatcher\JsonSchemaFieldInstanceMatcher::matchEntityPropsForScalar</code> there is logic to map bundles from a reference fields settings:</p> <pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // When &gt;1 bundle is specified, the above only matched base fields.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Iterate over all possible target bundles, set each on a clone of<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // $target, and hence repeat the same process as above &mdash; but exclude<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // base fields that are re-matched.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // @see \Drupal\Core\Entity\TypedData\EntityDataDefinition::getPropertyDefinitions()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $target_bundles = $field_definition-&gt;getItemDefinition()-&gt;getSettings()['handler_settings']['target_bundles'] ?? [];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (count($target_bundles) &gt; 1) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $base_field_names = array_keys($target-&gt;getPropertyDefinitions());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($target_bundles as $target_bundle) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assert($target-&gt;getBundles() === NULL);</pre><p>This code clones the entity data definition and sets the bundle explicitly for the target bundle. The problem is that cloning EntityDataDefinition does not reset the values in <code>\Drupal\Core\TypedData\ComplexDataDefinitionBase::$propertyDefinitions</code> which act as an object cache.</p> <h3 id="proposed-resolution">Steps to reproduce</h3> <p>Add Acquia DAM, without even having to be configured, and configure a media reference that targets all your media types explicitly.</p> <p>Here is an easier way to reproduce:</p> <p>* Have two taxonomy vocabularies<br> * Add a "Text (formatted)" to one of the vocabularies<br> * Add a reference field to a content type that references both vocabularies (do not use unlimited cardinality)</p> <p>Here's what HEAD does:</p> <p><img src="https://www.drupal.org/files/issues/2025-11-10/Screenshot%202025-11-10%20at%203.13.16%E2%80%AFPM.png"></p> <p>Here is with the fix</p> <p><img src="https://www.drupal.org/files/issues/2025-11-10/Screenshot%202025-11-10%20at%203.13.04%E2%80%AFPM.png"></p> <h3 id="proposed-resolution">Proposed resolution</h3> <p>The fix is to skip cloning and create a new value object:</p> <pre>$bundle_specific_target = EntityDataDefinition::create($target-&gt;getEntityTypeId(), $target_bundle);</pre><h3 id="ui-changes">User interface changes</h3>
issue