Problem/motivation

A file link loses its query string and fragment when the node edit form is reopened and saved using the Linkit widget.

Reproduced locally with Drupal 11.4.8, PHP 8.3.30 and Linkit 7.0.17. The same problem occurs on the current 7.x branch at 9a596950.

Steps to reproduce

  1. Add a Link field to a content type and select the Linkit widget and formatter.
  2. Configure the field's Linkit profile with a File matcher and upload a file.
  3. Edit a node and select the file from the autocomplete suggestions.
  4. Append ?download=1#page=2 to the selected URL, leave the field, and save.
  5. Check the rendered link. It contains the query string and fragment.
  6. Reopen the node edit form. Both parts are missing from the URL field.
  7. Save without changing the link. The saved link now also loses both parts.

Expected: The full file URL stays the same when reopening and saving the form.

Actual: /sites/default/files/document.pdf?download=1#page=2 becomes /sites/default/files/document.pdf.

As a comparison, manually pasting the complete URL without selecting a file reference preserved both parts on Linkit 7.0.17.

Proposed resolution

Preserve the query string and fragment when building the default URL for file entities in LinkitWidget::formElement(). The file entity branch generates only the file URL, while the following entity branch restores these options.

Related to #3359375, which fixed similar behaviour for internal entity links. This report covers file links selected through the File matcher.

Remaining tasks

Add a fix and regression coverage for reopening and saving file links with query parameters and fragments.

User interface changes

The existing URL field should retain the complete file URL.

API changes

None expected.

Data model changes

None expected.

AI disclosure: AI assisted with the investigation and local browser testing.

Comments

ishfaqafridi85 created an issue.