Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to get the route name through params #13

Open
mpdude opened this issue May 16, 2024 · 0 comments
Open

Make it possible to get the route name through params #13

mpdude opened this issue May 16, 2024 · 0 comments

Comments

@mpdude
Copy link
Member

mpdude commented May 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant