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

Find Controller related to Entity to generate admin url #6569

Open
damien-louis opened this issue Nov 25, 2024 · 6 comments
Open

Find Controller related to Entity to generate admin url #6569

damien-louis opened this issue Nov 25, 2024 · 6 comments

Comments

@damien-louis
Copy link
Contributor

I have a tool which log event for every entities. On my entity Log, I have fields EntityClass and EntityId.

Is there a way to find controller related to entity in twig to use it like this?

controller = xxxx.getControllerByEntity(entity.instance.entityClass)

<a href="{{ ea_url()
    .setController(controller)
    .setAction('detail')
    .setEntityId(entity.instance.entityId)
}}">
    {{ field.value[:8] }}...
</a>
@alexislefebvre
Copy link
Contributor

Do you use pretty URLs added in 4.15.0? https://github.com/EasyCorp/EasyAdminBundle/releases/tag/v4.15.0

It you don't, you may use something like this:

<a href="{{ path('admin', {
    crudAction: 'detail',
    crudControllerFqcn: 'App\\Controller\\Admin\\BadgeCrudController',
    entityId: entity.instance.entityId,
}) }}">Admin</a>

It will require some logic to point to the corresponding controller for each type of entity.


With pretty URLs, the URL is simpler:

<a href="{{ path('admin_badge_detail', {
    entityId: entity.instance.entityId,
}) }}">Admin</a>

The word in the middle of the name of the path is the name of the entity. Check the URLs in the admin to see how each entity's name is rendered.

@damien-louis
Copy link
Contributor Author

damien-louis commented Nov 25, 2024

You're second solution is good but what happen with many entities with same name in differents namespace ?

I want to use pretty urls, sure.

@alexislefebvre
Copy link
Contributor

You're second solution is good but what happen with many entities with same name in differents namespace ?

I want to use pretty urls, sure.

I don't know sorry, you'll have to check the name of the path generated by EasyAdmin.

@damien-louis
Copy link
Contributor Author

Currently, I use marcin-jozwikowski/easy-admin-pretty-urls and, this run well:

{{ ea_url()
    .setController(entity.instance.entityClass)
    .setAction('detail')
    .setEntityId(entity.instance.entityId)
}}

I set my Entity to setController() instead of ControllerFqdn and it works.

It's possible to implement same behavior or add something like setEntity() method?

@damien-louis
Copy link
Contributor Author

Can we envisage to have a twig function to find the detail route related to an entity?

@damien-louis
Copy link
Contributor Author

Seems indirectly fix by 8efaa68

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

2 participants