Problem/motivation
We ran into a problem when a link field was being rendered with ajax, such as a content type having a multi value paragraph field containing a link field. The site also needs a role where the permission "Link to any page" from the core system module is NOT set.
Steps to reproduce
- Install Drupal with Linkit 7.x and Paragraphs 1.19
- Create a user with a role that doesn't have the permission "Link to any page" set.
- Create a new paragraph type Test containing a Link field
- In the paragraph form display for test, set the Link field to use the Linkit widget, you can just use the default settings
- Create a content type Test with only one field; a paragraph field and allow the field to contain Test paragraphs
- Add a Test node
- Enter "hello broken world" or any other INVALID link in the Link field
- Click "Add Link"

Result
The steps above causes Drupal to crash with a 500 error, returning invalid code back to the AJAX form request. Further editing in the form might also be broken.
Proposed resolution
The issue is caused by getUrl in $item->getUrl()->access() not returning a valid URL and then the access for that object failing to get the access, since getUrl throws an InvalidArgumentException when it reaches the fromInternalUri function.
In the core LinkWidget.php class, they have resolved the issue by wrapping $item->getUrl()->access() in a try, catching the InvalidArgumentException and handling it gracefully.
The code in LinkWidget.php assigns a $display_uri, but I don't think we need to copy that part, as LinkitWidget.php doesn't seem to have the same assigning that LinkWidget.php has.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | Screen Recording 2025-07-08 at 13.47.53.gif | 539.42 KB | svenryen |
Issue fork linkit-3534671
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
svenryen commentedComment #4
svenryen commentedComment #5
svenryen commentedComment #6
svenryen commentedComment #9
mark_fullmerThis analysis is comprehensive and logical, and the proposed resolution of placing the executing code in a try/catch statement to avoid a fatal error, modeled after the behavior in Drupal core, is safe and uncontroversial. Thanks so much for the report, the analysis, and the code change fix!