Problem/Motivation

EntityInterface::url() is deprecated and it says to call toUrl() but if you do you get

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException with message 'No link template 'canonical' found for the 'file' entity type'

Proposed resolution

Add a canonical link template to file entities.

Remaining tasks

User interface changes

None

API changes

Hopefully none

Data model changes

None

Comments

alexpott created an issue. See original summary.

berdir’s picture

Not sure how you want to fix this exactly?

We could register a canonical link template/route that redirects to the actual file, but do we really want that?

Also note that file_entity *does* add a real canonical link template, with a standard entity view page that shows the file with the fields and so on.

alexpott’s picture

Well we're in a weird situation where ->url != ->toUrl()->toString(). If someone asked me what was the canonical link to a File entity I would say it was a link to the file.

larowlan’s picture

This feels familiar, is there an existing issue?

alexpott’s picture

larowlan’s picture

There is also #2355245: ER's label formatter needs to take into account that $entity->urlInfo() might throw an exception - I seem to recall it being an issue in DER - maybe I'm dreaming it.

Also related #2314509: RDF module prevents viewing of unsaved users (slightly)

berdir’s picture

I know that there's also another issue somewhere where I commented on, but can't find it anymore.

berdir’s picture

that's the one. this could be closed as a duplicate I think?

alexpott’s picture

Status: Active » Closed (duplicate)

Yes I agree.