Hi,
I have an entity called Setting which is only one row in the database table (added by doctrine fixtures) for manage all the settings (one column = one setting). I need only edit action to manage that one row my setting.yml config is:
easy_admin:
entities:
Setting:
disabled_actions: ['new', 'delete', 'list']
I've added custom menu option to link to edit settings page in menu.yml:
easy_admin:
design:
menu:
- label: 'Ustawienia'
- { label: 'Ustawienia', entity: 'Setting', params: { action: 'edit', id: 1 }, icon: 'wrench' }
And all works fine, but when I will submit edit action the controller wants to redirect to list action of Setting which is disabled of course and throws an exception:
Error: The requested "list" action is not allowed for the "Setting" entity. Solution: Remove the "list" action from the "disabled_actions" option, which can be configured globally for the entire backend or locally for the "Setting" entity.
I thought that I can change that behaviour through event system, but dispatch POST_UPDATE event not receive returned response in that line: https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Controller/AdminController.php#L217
Maybe is there any other option to change redirection after action in this great EasyAdminBundle which I don't know?
The simplest solution is to create your own AdminController (as explained in
https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/book/3-list-search-show-configuration.md#customizing-the-behavior-of-list-search-and-show-views) and override the editAction() method just for the Setting entity:
public function editSettingAction()
{
parent::editAction();
return $this->redirectToRoute('admin', ['entity' => 'Setting', 'action' => 'edit', 'id' => '1']);
}
It looks like redirection loop isn't it?
Thanks for advise, it works in this way:
public function editSettingAction()
{
$response = parent::editAction();
if ($response instanceof RedirectResponse) {
return $this->redirectToRoute('admin', ['entity' => 'Setting', 'action' => 'edit', 'id' => 1]);
}
return $response;
}
:+1:
Most helpful comment
Thanks for advise, it works in this way: