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

generateUrl is now final (still a problem) #7446

Closed tbyte80 closed 3 years ago

tbyte80 commented 3 years ago

I am referencing this issue for clarity:

https://github.com/sonata-project/SonataAdminBundle/issues/7441

Implementing RouteGeneratorInterface in custom Admin class is not possible because:

  1. generateUrl is defined in AbstractAdmin and is final. Implementing the interface doesn't allow to override that method.
  2. AbstractAdmin implements UrlGeneratorInterface which also has a function generateMenuUrl but incompatible to the one defined in RouteGeneratorInterface.
  3. I could override generate but generate is not called in CRUDController

Quite frankly I think declaring methods final causes a lot of friction with questionable benefits. Why hinder people overriding methods that are useful? If it's about maintenance why not at least declare them internal so people are aware of potential BC breaks.

VincentLanglet commented 3 years ago

It's not because I close the issue that you cant answer in it. Opening another one wont do anything.

You have to create another service to implement the RouteGeneratorInterface. And configure the admin class to use this service instead of the default one.

The generateUrl could basically be deprecated and removed as it's just an alias.

If you dont know how to do this, there is documentation, which might be improved but I think there is already section about how to override a service. And there is also a slack channel.