`format: uri` and `format: uri-reference` shape matching is too coarse, `StaticPropSource`s using the `link` field type allow incorrect values
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3542895. --> Reported by: [wim leers](https://www.drupal.org/user/99777) Related to !156 >>> <h3 id="overview">Overview</h3> <p>See <a href="https://opis.io/json-schema/2.x/formats.html#uri">https://opis.io/json-schema/2.x/formats.html#uri</a> vs <a href="https://opis.io/json-schema/2.x/formats.html#uri-reference">https://opis.io/json-schema/2.x/formats.html#uri-reference</a>.</p> <p><code>format: uri</code> allows only absolute URLs, <code>format: uri-reference</code> allows both absolute and relative URLs.</p> <h3 id="proposed-resolution">Proposed resolution</h3> <p>Refine both</p> <ol> <li>(static prop sources)<br> <pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // TRICKY: Drupal core does not support RFC3987 aka IRIs, but it's a superset of RFC3986.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // TRICKY: the `uri` and `iri` prop types will only pass validation with absolute paths, so we<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // instead use the link widget which is more permissive about the URI/IRI content.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // @see \Drupal\Core\Field\Plugin\Field\FieldType\UriItem<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // @see \Drupal\link\Plugin\Field\FieldType\LinkItem::defaultFieldSettings()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static::UriReference, static::Uri, static::IriReference, static::Iri =&gt; new StorablePropShape(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shape: $shape,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fieldTypeProp: new FieldTypePropExpression('link', 'url'),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // @see \Drupal\link\Plugin\Field\FieldType\LinkItem::defaultFieldSettings()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fieldInstanceSettings: [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // This shape only needs the URI, not a title.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'title' =&gt; 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fieldWidget: 'link_default',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ),</pre><ol> <li><code>format: uri|iri</code> &rarr; <code>LinkItemInterface::LINK_EXTERNAL</code></li> <li><code>format: uri-reference|iri-reference</code> &rarr; <code>LinkItemInterface::LINK_GENERIC</code></li> </ol> <p>&rarr; see #7. </p></li> <li>&#9989; <del>(dynamic prop sources)</del> already solved in <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3530351" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3530351</a></span>. </li> </ol> <h3 id="ui-changes">User interface changes</h3> <p>Drupal core's <code>LinkWidget</code> is now rendered for either <code>LINK_GENERIC</code> or <code>LINK_EXTERNAL</code>. Previously, it was always rendered for <code>LINK_GENERIC</code>, and hence allowed relative URLs to be entered even for props with <code>format: uri</code>. This bug is now solved.</p> <p><del>No more incorrect suggestions provided by <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>.</del> &rarr; already the UI effect since <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3530351" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3530351</a></span>.</p> > Related issue: [Issue #3540470](https://www.drupal.org/node/3540470) > Related issue: [Issue #3510896](https://www.drupal.org/node/3510896)
issue