Find optional field instance matches for `type: object` props (images + videos), including for optional fields on bundleless entity types (e.g. `User`'s `user_picture`)
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3541361. --> Reported by: [wim leers](https://www.drupal.org/user/99777) Related to !319 !242 >>> <h3 id="overview">Overview</h3> <p>Discovered while working on <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/experience_builder/issues/3510896" title="Status: Closed (fixed)">#3510896: Add a new internal HTTP API for candidate `DynamicPropSource`s to enable a `ContentTemplate` UI</a></span>.</p> <h3 id="proposed-resolution">Proposed resolution</h3> <h3 id="ui-changes">User interface changes</h3> <h4>Part one: Shape matching (<a href="https://git.drupalcode.org/project/canvas/-/merge_requests/242">MR !242</a>)</h4> <dl> <dt>Before</dt> <dd><img src="https://www.drupal.org/files/issues/2025-10-16/before.png"> <dd>(same for videos!) </dd></dd><dt>After</dt> <dd><img src="https://www.drupal.org/files/issues/2025-10-16/after.png"> <dd><img src="https://www.drupal.org/files/issues/2025-11-13/Screenshot%202025-11-13%20at%205.39.55%E2%80%AFPM.png"><br> </dd></dd></dl> <h4>Part two: Component source (<a href="https://git.drupalcode.org/project/canvas/-/merge_requests/319">MR !319</a>)</h4> <p>Fixing the above made many commonly optional fields for the first time available in the <code>ContentTemplate</code> UI. Consequently, it unveiled another bug: see #9.</p> <p>Basically: the SDC subsystem really doesn't like being given <code>"text" =&gt; NULL</code> for a <code>type: string</code> SDC prop called <code>text</code> that is optional &mdash; see core issue <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-1"><a href="https://www.drupal.org/project/drupal/issues/3531905" title="Status: Active">#3531905: Validation error on optional properties.</a></span>.<br> Fortunately, within Canvas, we can ensure we never do that. &#128077;</p> <dl> <dt>Before (#9)</dt> <dd><img src="https://www.drupal.org/files/issues/2025-10-16/Screenshot%202025-10-16%20at%201.01.15%20PM.png"> <pre>Twig\Error\RuntimeError occurred during rendering of component d9904f4d-3b6d-43c2-8312-8360f26299d7 in Content template Article content items &mdash; Full content view (node.article.full): An exception has been thrown during the rendering of a template ("[canvas_test_sdc:image-optional-with-example-and-additional-prop/image.src] NULL value found, but a string is required. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types.. [canvas_test_sdc:image-optional-with-example-and-additional-prop/image.alt] NULL value found, but a string is required. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types.. [canvas_test_sdc:image-optional-with-example-and-additional-prop/image.width] NULL value found, but an integer is required. [canvas_test_sdc:image-optional-with-example-and-additional-prop/image.height] NULL value found, but an integer is required.") in "canvas_test_sdc:image-optional-with-example-and-additional-prop" at line 1.</pre></dd> <dt>After (#11)</dt> <dd><img src="https://www.drupal.org/files/issues/2025-10-16/content%20template%20optional%20image%20object%20prop.gif"><br> </dd></dl> <h4>Part three: out of scope</h4> <p>&#128073; <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-15"><a href="https://www.drupal.org/project/canvas/issues/3557612" title="Status: Patch (to be ported)">#3557612: `::matchEntityPropsForObject()` is too na&iuml;ve: nonsensical `type: object` shape matches and useless labels</a></span></p> > Related issue: [Issue #3510896](https://www.drupal.org/node/3510896) > Related issue: [Issue #2169813](https://www.drupal.org/node/2169813) > Related issue: [Issue #3531905](https://www.drupal.org/node/3531905) > Related issue: [Issue #2577963](https://www.drupal.org/node/2577963) > Related issue: [Issue #3057545](https://www.drupal.org/node/3057545)
issue