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

Comments

keszthelyi created an issue. See original summary.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mohit_aghera’s picture

I 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

files will IMHO remain second-class citizens and we will not introduce an actual canonical route in core, and we decided against having one that points to the physical file.

I'm tagging for sub-system maintainer review to get second eyes.

kim.pepper’s picture

I don't think it qualifies as a bug if you manually put in a url with missing params.

mohit_aghera’s picture

Status: Active » Closed (won't fix)
Issue tags: -Needs subsystem maintainer review +Bug Smash Initiative

Closing this for now based on inputs from @kim.pepper

Feel free to reopen it if you notice further issues.