File delete form throws UndefinedLinkTemplateException without destination parameter

Created on 7 December 2023, over 1 year ago

Problem/Motivation

Since 10.1.0 it is possible to delete files โ†’ . The feature works using the delete button on the Files view, however when visiting the file delete form directly on /file/{file}/delete, without a destination parameter in the URL, this happens:

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'file' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 196 of core/lib/Drupal/Core/Entity/EntityBase.php).

Drupal\Core\Entity\ContentEntityDeleteForm->traitGetCancelUrl() (Line: 87)
Drupal\Core\Entity\ContentEntityDeleteForm->getCancelUrl() (Line: 42)
Drupal\Core\Form\ConfirmFormHelper::buildCancelLink(Object, Object) (Line: 88)
...

The cause of the issue is that ConfirmFormHelper::buildCancelLink() checks for a route-based cancel link if there's no destination, calling ContentEntityDeleteForm->getCancelUrl() .

Steps to reproduce

On a newly installed Drupal 10.1.7 site, where Image module is enabled, create a content type with an image field.
Make sure your account has permission to 'delete own files'.
Add a node and upload an image to the field.
Visit /file/1/delete

Proposed resolution

Possibly, adding a canonical link template to file entity. This was proposed previously โ†’ , but at the time the decision was not to add it.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

Active

Version

10.1 โœจ

Component
File moduleย  โ†’

Last updated 17 days ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium keszthelyi Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024