をリンクする前に、カスタム・ロジックを追加するには、次へSonataAdmin - 私たちは私たちのエンティティの管理クラスで、OUビューリストでのおかげで私たちが望むアクションリンクをカスタマイズすることができます知っているどのように特定のアクションを表示する
$listMapper
->addIdentifier('name')
->add('minRole')
->add('_action', null, [
'actions' => [
'show' => [],
'edit' => [],
'delete' => []
]
])
;
をやロールを管理感謝サービスは:sonata.admin.security.handler.role
私の場合は(それがビューリストと編集ビューに表示されます)[削除]ボタンを表示するかしないために、ドメインロジックを追加したいと思います。
{% if attribute(object, hasEvents) is defined and not object.hasEvents %}
# display it
{% endif %}
私はSonataの小枝テンプレートをオーバーライドする方法を知りません。 2つのエンティティ:Event
とPost
のみが対象です。 ビューリストため
EDIT
私が直接list__action_delete.html.twig
テンプレートをオーバーライドする(私はapp/Resources/SonataAdminBundle/views/CRUD/list__action_delete.html.twig
を作成した)、これはコード(私はそれが最善の方法ではありません知っている...)です:
{#
The template override the basic one in order to prevent the display of the delete button (in the view list) for the entities
Post and Event. We only display it if they don't have associated activities.
#}
{% if admin.isGranted('DELETE', object) and admin.hasRoute('delete') %}
{% if not attribute(object, 'isDeleteable') is defined %}
<a href="{{ admin.generateObjectUrl('delete', object) }}" class="btn btn-sm btn-default delete_link" title="{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}">
<i class="fa fa-times"></i>
{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}
</a>
{% else %}
{% if object.isDeleteable %}
<a href="{{ admin.generateObjectUrl('delete', object) }}" class="btn btn-sm btn-default delete_link" title="{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}">
<i class="fa fa-times"></i>
{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}
</a>
{% endif %}
{% endif %}
{% endif %}
あなたの明確な答えをいただきありがとうございます。編集ページでは完全に動作しますが、代わりに 'sonata_form_actions'ブロックを使用しました:) –