Closed grekpg closed 5 years ago
parameters:
sonata.admin.global_template_registry: App\Service\SonataTemplateRegistry
this won't work because we aren't using parameters to define class of the global_template_registry:
Alternative is to decorate it https://symfony.com/doc/current/service_container/service_decoration.html
Thanks for respond.
i try this:
mea.sonata.admin.global_template_registry:
class: App\Service\SonataTemplateRegistry
decoration_inner_name: Sonata\AdminBundle\Templating\TemplateRegistry
decorates: sonata.admin.global_template_registry
public: true
arguments: ['%sonata.admin.configuration.templates%', '@mea.contact']
also i try manualy put to admin my template registry
app.admin.social.text.templates:
class: App\SocialManager\Admin\TextTemplatesAdmin
arguments: [~, App\SocialManager\Entity\TextTemplate,~]
tags:
- { name: sonata.admin, manager_type: orm, label: "Text Templates" }
public: true
calls:
- [ setTemplateRegistry, ['@mea.sonata.admin.global_template_registry']]
but still in admin
protected function configureListFields(ListMapper $listMapper)
{
dump($this->getTemplateRegistry());
give my Sonata\AdminBundle\Templating\TemplateRegistry
I try decorate
decoration_inner_name: Sonata\AdminBundle\Templating\TemplateRegistry
decorates: sonata.admin.global_template_registry
like that
mea.sonata.admin.global_template_registry:
class: App\Service\SonataTemplateRegistry
decoration_inner_name: Sonata\AdminBundle\Templating\TemplateRegistry
decorates: sonata.admin.global_template_registry
public: true
arguments: ['%sonata.admin.configuration.templates%', '@mea.contact']
You ask that i try decorate - template registry admin child - no , because i need globaly change it so in this way i need to do this for all admins. But why
calls:
- [ setTemplateRegistry, ['@mea.sonata.admin.global_template_registry']]
Also dont work ? I correct try decorate main template registry ?
but yes - this work
mea.sonata.admin.global_template_registry:
class: App\Service\SonataTemplateRegistry
decorates: app.admin.social.text.templates.template_registry
public: true
arguments: ['%sonata.admin.configuration.templates%', '@mea.contact']
but this is not global, is possible to globally set template registry without creating new template registry for all admin classes ?
FYI: this is still an issue..
is possible to globally set template registry without creating new template registry for all admin classes
This is exactly what I've been attempting to do. I want to pass a different TemplateRegistry per Admin however it's not possible. Every AdminClass despite getting set, is then injected witht he default TemplateRegistry.
In SonataAdminBundle
3.x template registry is auto generated by AddDependencyCallsCompilerPass
with global (sonata) configuration. Evan if you call setTemplateRegistry
the registry will be override.
I working on it and it should be done in #6566 (Auto generate will be done when setTemplateRegistry
is not call).
For now you can create own compiler pass to override template registry or set it after containier configuration.
Environment
docker ubuntu
Sonata packages
Symfony packages
PHP version
Subject
I register my own global_template_registry - I need switch template depends of logged user. (I implement bootsrap 4 its ready for simple part, rest admins must use v3 standard layout.
in any admin class
i get
Sonata\AdminBundle\Templating\TemplateRegistry
not like i setupApp\Service\SonataTemplateRegistry
I found in
vendor/sonata-project/admin-bundle/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php
Expected results
load correct global template registry
Here is stackoverflow question about this https://stackoverflow.com/questions/55530510/sonata-admin-override-template-depend-of-user