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

  1. Install Drupal with Linkit 7.x and Paragraphs 1.19
  2. Create a user with a role that doesn't have the permission "Link to any page" set.
  3. Create a new paragraph type Test containing a Link field
  4. In the paragraph form display for test, set the Link field to use the Linkit widget, you can just use the default settings
  5. Create a content type Test with only one field; a paragraph field and allow the field to contain Test paragraphs
  6. Add a Test node
  7. Enter "hello broken world" or any other INVALID link in the Link field
  8. Click "Add Link"

Screen recording showing the error thrown by a malfunctioning Linkit module

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.

Issue fork linkit-3534671

Command icon 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

svenryen created an issue. See original summary.

svenryen’s picture

Status: Active » Needs review

svenryen’s picture

Issue summary: View changes
StatusFileSize
new539.42 KB
svenryen’s picture

Issue summary: View changes
svenryen’s picture

Issue summary: View changes

mark_fullmer made their first commit to this issue’s fork.

mark_fullmer’s picture

Status: Needs review » Fixed

This 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!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.