My custom content Entity overrides label() to provide a dynamically generated, human-readable label like:
public function label() {
return $this->displayName();
}
Unfortunately, that label does not get used by the EntityViewController. In my module.routing.yml file I have:
entity.veranstaltung.canonical:
path: '/admin/veranstaltung/{veranstaltung}'
defaults:
_entity_view: 'veranstaltung'
requirements:
_entity_access: 'veranstaltung.view'
I can now view my "veranstaltung" entities, but the page title is blank and the breadcrumb just shows the entity's id instead of its label.
Looking in EntityViewController::buildTitle() I can now see why this is the case:
$label_field = $entity->getEntityType()->getKey('label');
if (isset($page[$label_field])) {
$page['#title'] = $this->renderer->render($page[$label_field]);
}
I don't have a label key, as I want the labels to be dynamically generated.
Any suggestions how to best deal with this problem?