File delete form throws UndefinedLinkTemplateException without destination parameter

Created on 7 December 2023, 6 months 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 3 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.69.0 2024