Assume we have two entity types with a 1:n relationship, e.g. an Event type that has a number of Participants that belong to that type. I have implemented this such that Participant has an entity_reference field that specifies the Event.
Now I would like to change the dependent (Participant) entity's add_form route, so that I can easily add Participants to an Event:
@ContentEntityType(
id = "participant",
// ...
links = {
"add-form" = "/admin/structure/event/{event}/participants/add",
// ...
},
I've managed to make this work on the AddForm. But now I get lots of routing errors like this in other places (such as when deleting a participant entity):
Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("event") to generate a URL for route "entity.participant.add_form".
The add_form route comes from DefaultHtmlRouteProvider. I've tried overriding it with a static route that includes a default value:
entity.participant.add_form:
path: '/admin/structure/event/{event}/participant/add'
defaults:
_title: 'Add participant'
_entity_form: participant.add
event: NULL
but this doesn't work – page not found.
What would be the best way to supply a default value, or is there a better way to handle this kind of entity relationship?