Assume you can archive BlogPost instances, and you need to use different route names for archived blog posts. For example, the blog_detail route might be at /blog/{slug}, but blog_archived is at /archive/{slug}.
It would be nice if you could still write {{ object_route(post, 'detail') }} in Twig and make the object route figure out whether to use blog_detail or blog_archived.
To make this possible, we could allow to omit the name configuration parameter from @ObjectRoute under the condition that the set of parameters obtained through params contains a _route param. If that is the case, use _route as the route name.
We should fail if either name is provided and a _route is returned, or if neither one is present.
Admittedly, the motivating use case would require that the BlogPost object itself can make the distinction:
@ObjectRoute(type="detail", params={"_route": "routeName"}) -> calls BlogPost::getRouteName()
However, in combination with #12 the full flexibility could be put into the ObjectRoute declaration.
Assume you can archive
BlogPostinstances, and you need to use different route names for archived blog posts. For example, theblog_detailroute might be at/blog/{slug}, butblog_archivedis at/archive/{slug}.It would be nice if you could still write
{{ object_route(post, 'detail') }}in Twig and make the object route figure out whether to useblog_detailorblog_archived.To make this possible, we could allow to omit the
nameconfiguration parameter from@ObjectRouteunder the condition that the set of parameters obtained throughparamscontains a_routeparam. If that is the case, use_routeas the route name.We should fail if either
nameis provided and a_routeis returned, or if neither one is present.Admittedly, the motivating use case would require that the
BlogPostobject itself can make the distinction:@ObjectRoute(type="detail", params={"_route": "routeName"})-> callsBlogPost::getRouteName()However, in combination with #12 the full flexibility could be put into the
ObjectRoutedeclaration.