答案 0 :(得分:2)
你必须在override the default template
中使用自己的coding your logique here (布局:'SonataAdminBundle :: standard_layout.html.twig')以下是现有代码的摘录:
{% block sonata_admin_content_actions_wrappers %}
{% if _actions|replace({ '<li>': '', '</li>': '' })|trim is not empty %}
<ul class="nav navbar-nav navbar-right">
{% if _actions|split('</a>')|length > 2 %}
<li class="dropdown sonata-actions">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ 'link_actions'|trans({}, 'SonataAdminBundle') }} <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
{{ _actions|raw }}
</ul>
</li>
{% else %}
{{ _actions|raw }}
{% endif %}
</ul>
{% endif %}
{% endblock sonata_admin_content_actions_wrappers %}
答案 1 :(得分:0)
它需要添加自定义操作并覆盖某个模板。您可以关注documentation on symfony.com。
阅读以下代码块:
{# src/AppBundle/Resources/views/CRUD/list__action_clone.html.twig #}
<a class="btn btn-sm" href="{{ admin.generateObjectUrl('clone', object)}}">clone</a>
答案 2 :(得分:0)
我刚遇到同样的问题。我正在使用 Symfony 3.4.6 和 Sonata Admin Bundle 3.9.1 。这些是我遵循的步骤:
1. Find the standard template which lives in:/vendor/sonata-project/admin-bundle/src/Resources/views/standard_layout.html.twig.
2. Go to /app/config/config.yml and under the key sonata_admin, you just override that template as shown below
sonata_admin:
templates:
# Layout
layout: '@MyBundle/Admin/Default/Layout/standard_layout.html.twig'
3. Within your newly created template (standard_layout.html.twig) make sure you have extended the sonata standard template file like so : {% extends '@SonataAdmin/standard_layout.html.twig' %}. Now, all you need to do is override any block you want from the original sonata template file as I described in point 1, in my case I've just overridden the block tab_menu_navbar_header and Added my custom button like so:
{% block tab_menu_navbar_header %}
{% if _navbar_title is not empty %}
<div class="navbar-header">
<a class="navbar-brand" href="#">{{ _navbar_title|raw }}</a>
{% if object.state is defined and object.state is not null and object.state is same as('finished') %}
<button type="button" class="btn btn-info" style="margin-top: 10px;">
<i class="fa fa-check-square" aria-hidden="true"> History</i>
</button>
{% endif %}
</div>
{% endif %}
{% endblock %}