質問

I'm currently using SonataAdminBundle for the creation of a Back Office and I've integrated SonataMediaBundle (app-dev version) 2 days ago. The edit/create template from sonata bundle however has some errors! I've fixed them (and they are just twig errors).

But I can't just make the changes in the vendor. What is the correct way to overwrite the SonataMediaBundle templates?
I've tried the classic AdminBundle way but it doesn't work! here's the code:

sonata.admin.media:
        class: Acme\AdminBundle\Admin\MediaAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Media Library", label: "Media" }
        arguments:
            - ~
            - ~
            - ~
            - @sonata.media.pool
        calls:
            - [ setTemplate, [edit, AcmeAdminBundle:Media:edit.html.twig]] 
役に立ちましたか?

解決

Actually, now I've figured it out. In order to overwrite the media Preview or form, you should overwrite the form widget, or customize your form theme.

Example: In the config.yml file add the configuration:

twig:
    form:
        resources:
            # other files
            - 'AdminBundle:Form:mediaPreview.html.twig'

The media preview file should look something like this:

{% block sonata_media_type_widget %}
      << your code here >>
{% endblock sonata_media_type_widget %}

他のヒント

You overwrite them in the same way you would any other bundle except Sonata use's easy extends so in App/Resources create a folder called ApplicationSonataMediaBundle or ApplicationSonataAdminBundle and inside this folder create a folder of the same name as the one you are trying to override.

For example I currently use the following:

App/Resources/ApplicationSonataNewsBundle/translations/SonataNewsBundle.en.xliff

To override any of the English translations in their news bundle OR

App/Resources/ApplicationSonataUserBundle/views/layout.html.twig

To override their Layout template.

I would suggest you need to create something along these lines.

App/Resources/ApplicationSonataMediaBundle/views/MediaAdmin/edit.html.twig

and copy the Sonata code into it, then modify as you require.

Hope this helps

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top