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.
Comments
Comment #2
keszthelyi commentedComment #4
mohit_aghera commentedI believe it is intentionally that file entities don't have canonical route.
As @berdir mentioned in comment https://www.drupal.org/project/drupal/issues/2345761#comment-13180034
I'm tagging for sub-system maintainer review to get second eyes.
Comment #5
kim.pepperI don't think it qualifies as a bug if you manually put in a url with missing params.
Comment #6
mohit_aghera commentedClosing this for now based on inputs from @kim.pepper
Feel free to reopen it if you notice further issues.