Skip to content

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

@mpdude

Description

@mpdude

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions