19.
Conditional Actions
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
4 Comments
Hey Ryan, great work on the videos!
I was wondering how you can dynamically remove the delete action from the edit view? It's seems to be baked into the form itself...
Hey screon
Do you need to remove the delete action only if certain logic applies to the given object or is it more general ? Because you could remove the action in the config.yml file. Something like this:
I hope it helps you, cheers!
Thanks for the suggestion! But I need to apply some logic on user role basis. In the video we've conditionally hidden the delete action on the list and show views, but it didn't mention anything about the edit view, where the delete button is still visible. So basically: if user doesn't have role_admin, hide the delete button. But only for that specific entity.
Hey screon ,
The way is the same as we did with EasyAdminExtension::filterActions() in this video. Actually, you just need to find a proper Twig template, override it and implement whatever crazy logic you need. You can do it just with is_granted() Twig function in the template, or create a custom Twig filter/function, move complex checking logic there and call it from the overridden template (similar to ours filterActions()).
Or, you know, take a look at JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController::createDeleteForm(). Probably you just can to override this method and hide the button there.
Cheers!
"Houston: no signs of life"
Start the conversation!