SonataUserBundle
SonataUserBundle copied to clipboard
Include how to override Sonata User admin service in Documentation
Subject
I am targeting this branch, because Sonata User documentation is missing a passage on how to override service just like Sonata Admin documentation,
Changelog
### Added
- Added example of overriding service in documentation
Do we have to repeat the tags ? Also this is following the standard way of overriding service from Symfony, so I'm not sure it requires extra-doc ; isn't it ?
Do we have to repeat the tags ? Also this is following the standard way of overriding service from Symfony, so I'm not sure it requires extra-doc ; isn't it ?
That's true that it's a standard in overriding services, it was just an example to show the specific parameters to override sonata user services. Just like how Sonata Admin documentation shows examples of specific admin, figured it would save people time. If it's not needed then it's fine.
but isn't it easier to configure the admin service over the admin->user->class configuration?
with that you can change the admin without touching the service?
but isn't it easier to configure the admin service over the admin->user->class configuration?
with that you can change the admin without touching the service?
Are you referring to autowire, autoconfigure attributes? Though I did try using Dependency Injection attribute, doesn't seems to work for me properly.
In the end just passing a argument via through service was consistent, considering all my other admin are declared from services.yaml.
but isn't it easier to configure the admin service over the admin->user->class configuration? with that you can change the admin without touching the service?
Are you referring to autowire, autoconfigure attributes? Though I did try using Dependency Injection attribute, doesn't seems to work for me properly.
In the end just passing a argument via through service was consistent, considering all my other admin are declared from services.yaml.
i meant this config option: https://github.com/sonata-project/SonataUserBundle/blob/5.x/src/DependencyInjection/SonataUserExtension.php#L101
this sets the class for the sonata.user.admin.user
service
should be
sonata_user:
admin:
user:
class: ClassNameThere
but isn't it easier to configure the admin service over the admin->user->class configuration? with that you can change the admin without touching the service?
Are you referring to autowire, autoconfigure attributes? Though I did try using Dependency Injection attribute, doesn't seems to work for me properly. In the end just passing a argument via through service was consistent, considering all my other admin are declared from services.yaml.
i meant this config option: https://github.com/sonata-project/SonataUserBundle/blob/5.x/src/DependencyInjection/SonataUserExtension.php#L101
this sets the class for the
sonata.user.admin.user
serviceshould be
sonata_user: admin: user: class: ClassNameThere
Yeah I know about class configuration option, it's on the same page as that document. I don't think there is a option for passing services into the configuration option. For example I need to send a service into the Admin, such as @security.token_storage for the admin to display a custom view if the user is itself.
have you tried to use setter autowiring?
https://symfony.com/doc/current/service_container/calls.html https://symfony.com/doc/current/service_container/autowiring.html#autowiring-calls
have you tried to use setter autowiring?
https://symfony.com/doc/current/service_container/calls.html https://symfony.com/doc/current/service_container/autowiring.html#autowiring-calls
It's simpler to just override the Sonata User admin service, to include missing services. For controllers I just amend getSubscribedServices(), to include services.
The documentation of amending Sonata User admin service, was missing. Just figured that people may want to know how to do it, just like Sonata Admin documentation explains how to amend admin services. But this PR is specifically for Sonata User bundle... hence the PR.