I've created a custom content entity with drush generate module-content-entity
, which works great. However, I want my custom entities NOT to have a canonical url. Drush automatically creates those in the annotation of the entity class:
/**
* Defines the chunk entity class.
*
* @ContentEntityType(
* id = "chunk",
* ...
* links = {
* "add-form" = "/admin/content/chunk/add/{chunk_type}",
* "add-page" = "/admin/content/chunk/add",
* "canonical" = "/chunk/{chunk}",
* "edit-form" = "/admin/content/chunk/{chunk}/edit",
* "delete-form" = "/admin/content/chunk/{chunk}/delete",
* "collection" = "/admin/content/chunk"
* },
* ...
* )
*/
I've tried to remove the canonical entry from the annotation, but this resulted in numerous errors left and right, because a lot of core and contrib modules assume that canonical URLs always exist. In my case most of those errors are coming from other modules calling functions that end up in EntityBase::toUrl
, which fails with a WSOD due the missing canonical entry.
Even though this seems to be mandatory (@see EntityTypeInterface), some others - e.g. Paragraphs module - somehow managed to remove the canonical link, without causing errors everywhere.
Can anybody give me some hints how to safely remove the canonical link from my custom content entity? I do not want to turn the canonical links into 403's or 404's, I'd prefer those links not ever being rendered at all (hide "View" primary tab, prevent links when rendering entity labels, etc).
EntityBase::toLink / ::toUrl
, which is called by other modules and fails with an WSOD when removing the canonical entry from the annotation