How do I override the sonata_type_model_list_widget template?

705 views
Skip to first unread message

Florin

unread,
Mar 26, 2014, 2:45:11 PM3/26/14
to sonata...@googlegroups.com
How can I override the template doctrine-orm-admin-bundle/Resources/views/Form/form_admin_fields.html.twig in order to change the template for one of the fields (sonata_type_model_list_widget) and javascripts?

Florin

unread,
Mar 26, 2014, 2:46:08 PM3/26/14
to sonata...@googlegroups.com
I need to do it from inside my bundle (no app/ changes)

Cassiano Tartari

unread,
Mar 26, 2014, 3:15:12 PM3/26/14
to sonata-users

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.

Florin

unread,
Mar 26, 2014, 3:34:48 PM3/26/14
to sonata...@googlegroups.com
No, I can't use the app folder nor bundle inheritance. What I could do is put this into config.yml:


sonata_doctrine_orm_admin:
    templates:
        form: [ WyzbizMainBundle:Form/orm:form_admin_fields.html.twig ]

As written here http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/templates.html

but it's not working; it keeps loading the default file.

Florin

unread,
Mar 26, 2014, 4:06:46 PM3/26/14
to sonata...@googlegroups.com

I've set the bundle's proper config.yml entry, but it's not working.

Cassiano Tartari

unread,
Mar 26, 2014, 4:21:29 PM3/26/14
to sonata-users
The templates from sonata_admin in config are only those called by the method getTemplate from admin class if I'm not wrong.

You can override the service responsible for sonata_type_model_list_widget and than set your own template.

vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Form/Type/ModelTypeList.php

Add in your bundle services:

<service id="sonata.admin.form.type.model_list" class="Company\MyBundle\Form\Type\MyModelTypeList">
    <tag name="form.type" alias="sonata_type_model_list" />
</service>



Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


Florin

unread,
Mar 27, 2014, 3:55:06 AM3/27/14
to sonata...@googlegroups.com
I have just overriden the service using a compiler pass, but I still don't see how this will help me change the templates now
Reply all
Reply to author
Forward
0 new messages