`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> // TRICKY: Drupal core does not support RFC3987 aka IRIs, but it's a superset of RFC3986.<br> // TRICKY: the `uri` and `iri` prop types will only pass validation with absolute paths, so we<br> // instead use the link widget which is more permissive about the URI/IRI content.<br> // @see \Drupal\Core\Field\Plugin\Field\FieldType\UriItem<br> // @see \Drupal\link\Plugin\Field\FieldType\LinkItem::defaultFieldSettings()<br> static::UriReference, static::Uri, static::IriReference, static::Iri => new StorablePropShape(<br> shape: $shape,<br> fieldTypeProp: new FieldTypePropExpression('link', 'url'),<br> // @see \Drupal\link\Plugin\Field\FieldType\LinkItem::defaultFieldSettings()<br> fieldInstanceSettings: [<br> // This shape only needs the URI, not a title.<br> 'title' => 0,<br> ],<br> fieldWidget: 'link_default',<br> ),</pre><ol>
<li><code>format: uri|iri</code> → <code>LinkItemInterface::LINK_EXTERNAL</code></li>
<li><code>format: uri-reference|iri-reference</code> → <code>LinkItemInterface::LINK_GENERIC</code></li>
</ol>
<p>→ see #7.
</p></li>
<li>✅ <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> → 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