Reputation: 31
I am using EasyAdminBundle in Symfony 3.1.9.
I managed to customize actions in lists, as well explained here: https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/tutorials/custom-actions.md
But I didn't found any documentation to add custom entity action in forms.
My goal is to add, near the "Save", "Delete" and "Back to list" buttons, a button which saves current entity and redirect to the current edit form (not return to list as default behavior).
Thank you in advance
Upvotes: 0
Views: 4002
Reputation: 31
I've probalby made something dirty but it works.
I've overwrited the editAction :
public function editAction()
{
$response = parent::editAction();
if ($response instanceof RedirectResponse) {
$request = Request::createFromGlobals();
return $this->redirect(urldecode($request->request->get('referer')));
}
return $response;
}
The method $this->getCurrentEntity() were unknown.
I've also overwrited the edit.html.twig to add another button next to the basic one with jQuery:
var cloned = $( "button.action-save" );
var clone = cloned.clone();
cloned.after(clone);
clone.addClass('action-save-stay')
clone.html('<i class="fa fa-save"></i>{{ 'action.save_stay'|trans }}');
$('.action-save-stay').bind('click', function(e) {
e.preventDefault();
$('input[name="referer"]').val(window.location.href);
$('form').submit();
});
It changes the hidden input named referer. By default, easyadmin redirects to the referer contained in the query string.
Thank you so much to put me in the right direction.
Upvotes: 1
Reputation: 970
Olivier If your goal is just to redirect back to edit action of same entity form instead of redirection to list action. It's quite simple like this. Let's assume You are on new action of Product entity and want back to edit after saving new product.
public function newProductAction()
{
$response = parent::newAction();
if ($response instanceof RedirectResponse) {
$entity = $this->getCurrentEntity();
return $this->redirectToRoute('admin', [
'entity' => 'Product',
'action' => 'edit',
'id' => $entity->getId()
'menuIndex' => 1
]);
}
return $response;
}
Here 2 points keep in mind menuIndex is for active menu class so, it may be changed as per your sequence. And redirect route 'admin' should be your easyadmin backend route.
Upvotes: 0