[英]Custom action in the edit view of sonata admin Bundle
I'm working with sonata Admin Bundle and I want to add a custom action in the edit view just like ( Update Update and close or Delete). 我正在使用Sonata Admin Bundle,并且想在编辑视图中添加自定义操作,就像(Update Update and close或Delete)一样。 I searched, but I didn't find a solution.
我进行了搜索,但没有找到解决方案。 I did this before but in the list View.
我之前做过,但是在列表视图中。 I have tried to make the same thing in this case by following this answer SonataAdmin custom form action but it does not work and I got this error
在这种情况下,我尝试通过遵循此答案SonataAdmin自定义表单操作来做相同的事情,但是它不起作用,并且出现此错误
Could not load type "actions" when I add
我添加时无法加载类型为“动作”的信息
->add('_action', 'actions', array(
'actions' => array(
'view' => array('template' => 'ATSAdminBundle:CRUD:form__action_confirmation.html.twig')
)
))
;
in the 在里面
configureFormFields()
configureFormFields()
Any one can help me to do this plz ? 任何人都可以帮助我做到这一点吗?
This is because configureFormFields()
doesn't accept this entry. 这是因为
configureFormFields()
不接受该条目。 You can do this only in configureListFields()
. 您只能在
configureListFields()
执行此操作。
If you want to add an action in the edit form, like the buttons: "Update", "Update and close" or "Delete", then you have to override the following template: 如果要在编辑表单中添加操作,例如按钮:“更新”,“更新并关闭”或“删除”,则必须覆盖以下模板:
vendor/sonata-project/admin-bundle/Resources/views/CRUD/base_edit_form.html.twig
Copy this file in app/Resources/SonataAdminBundle/views/CRUD
将此文件复制到
app/Resources/SonataAdminBundle/views/CRUD
and add your action in the {% block formactions %}
, something like this: 然后将您的操作添加到
{% block formactions %}
,如下所示:
{% if admin.hasroute('view') %}
<a class="btn btn-success" href="{{ admin.generateObjectUrl('view', object) }}">View</a>
{% endif %}
This is just an example to point you to the right direction. 这只是一个指引您正确方向的示例。 You have to adapt it.
您必须适应它。
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.