Routing for dependent entities 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?
A default value does not work in this case, as - strangely - this will override the context provided event id. Some default entity methods, such as delete, seem to require the route URLs and therefore fail when the parameter is not given.

The add_form route, which is automatically created by DefaultHtmlRouteProvider from the @ContentEntityType annotation, causes problems here. The easiest solution is probably to remove this route by deleting the line

"add-form" = "/admin/structure/event/{event}/participants/add"


from @ContentEntityType (under "links") – do not remove the add form in section "form" – and providing the route in modulename.routing.yml:

entity.participant.add_form:
  path: '/admin/structure/event/{event}/participant/add'
  defaults:
    _entity_form: participant.add
    entity_type_id: 'participant'
    _admin_route: TRUE
  requirements:
    _entity_create_access: 'participant'