sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Using SubClasses in admins create either not handable translation ids or urly urls #8128

Closed BA-JBI closed 5 months ago

BA-JBI commented 11 months ago

Problem

Rererring to: https://symfony.com/bundles/SonataAdminBundle/current/reference/advanced_configuration.html#inherited-classes

Variant A

App\Admin\ExampleAdmin:
    tags:
        -   name:            sonata.admin
#            [...]
    calls:
      - ['setSubClasses', [{
             class_a: App\Entity\SubClassA,
             class_b: App\Entity\SubClassB
      }]]

Is resulting in image image

Those translation labels are not great to handle


Variant B

App\Admin\ExampleAdmin:
    tags:
        -   name:            sonata.admin
#            [...]
    calls:
      - ['setSubClasses', [{
             app.my_class.subclass.class_a: App\Entity\SubClassA,
             app.my_class.subclass.class_b: App\Entity\SubClassB
      }]]

creates nice translation labels but ugly create url:

https://my.app.example/admin/entity/namespace/create?subclass=app.my_class.subclass.class_a

My suggested solution:

https://github.com/sonata-project/SonataAdminBundle/blob/75d71162b5bdd590afc105bcd0e8112f4cced224/src/Resources/views/Button/create_button.html.twig#L25

Change to:

                    {{ 'link_action_create'|trans({}, 'SonataAdminBundle') }} {{ admin.translationLabel(subclass,'subclass')|trans({}, admin.translationDomain) }}
VincentLanglet commented 11 months ago

That would be a BC break and would require a new major version. Doesn't seems worth it.

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.