简体   繁体   English

如何覆盖Sonata Media Bundle模板?

[英]How to override Sonata Media Bundle templates?

I'm currently using SonataAdminBundle for the creation of a Back Office and I've integrated SonataMediaBundle (app-dev version) 2 days ago. 我目前正在使用SonataAdminBundle创建后台,并且SonataMediaBundle已经集成了SonataMediaBundle (应用程序开发版本)。 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? 覆盖SonataMediaBundle模板的正确方法是什么?
I've tried the classic AdminBundle way but it doesn't work! 我已经尝试了经典的AdminBundle方式,但是它不起作用! 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: 示例:在config.yml文件中添加配置:

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. 您以与其他捆绑软件相同的方式覆盖它们,除了Sonata使用的易扩展性外,因此在App / Resources中创建一个名为ApplicationSonataMediaBundle或ApplicationSonataAdminBundle的文件夹,并在此文件夹中创建与您要覆盖的文件夹同名的文件夹。

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. 并将Sonata代码复制到其中,然后根据需要进行修改。

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM