If a view mode is set to have an onclick attribute, whose value comes from a token that gives an external url, an uncaught InvalidArgumentException is thrown.
This is happening because DS supposes that the token will return an internal uri, which is not always the case.
Example case: The entity has a link field, which has an external url in the link's value.
The problem is in ds.module @ line 561 :
$url = Url::fromUri('internal:/' . $url);
This supposes that the $url will always be internal.
Steps to reproduce:
- Create a link field to a node (or any other entity)
- Create a node and type an external url to this field, for example
https://www.drupal.org
- Go to
admin/structure/types/manage/YOUR_NODE_BUNDLE/display and select a Display Suite layout
- At the Custom wrappers select Add link > Tokens and in the Custom link use your field token:
[node:field_link:uri]
Now if you clear caches and try to visit your node, you will get a WSOD with InvalidArgumentException:
The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: The internal path component 'https://www.drupal.org' is external. You are not allowed to specify an external URL together with internal:/. in <em class="placeholder">Drupal\Core\Url::fromInternalUri()</em> (line <em class="placeholder">410</em> of <em class="placeholder">core/lib/Drupal/Core/Url.php</em>). <pre class="backtrace">Drupal\Core\Url::fromUri('internal:/https://www.drupal.org') (Line: 561)
Comments
Comment #2
efpapado commentedAttaching patch.
Comment #3
aspilicious commentedWe need a test for this so we don't brake this again in the future. (both internal and external url)
Comment #4
aspilicious commentedComment #5
karlsheaIf you're using a LinkIt field the URI already has "internal:/" prepended, so that needs to be checked as well.
Comment #6
karlsheaAlso support entity: protocol
Comment #7
karlsheaOops!
Comment #8
swentel commentedgo bot
Comment #9
swentel commentedLooks good (tested manually too).
We do need tests though,
Comment #10
swentel commentedFixed in #2883928: Use absolute or external URL for link wrappers (without tests, but was fine manually)