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). 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
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()
Any one can help me to do this plz ?
This is because configureFormFields()
doesn't accept this entry. You can do this only in 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
and add your action in the {% block formactions %}
, something like this:
{% 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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.