Skip to content
Advertisement

Sonata Admin: how validate remove action?

How check conditions before remove action and set flash message in sonata-admin?

I do not want remove super-user. My current code:

JavaScript

Its throw exception. I need send flash message in admin-panel.

Advertisement

Answer

Thank you Ryuk Lee, He made me research the code 🙂

Solution:

JavaScript

ModelManagerException – This is an exception that will make the sonata work properly. Do not delete the object and write a error message in the admin panel, without “success” message. Work only debug = false.

JavaScript

But I met a problem, toogle error messages (“more”):

enter image description here

2 solutions:

1) override template

config.xml

JavaScript

layout.html.twig

JavaScript

flash_messages.html.twig

JavaScript

Result:

enter image description here

2) Override Admin controller.

serivices.yml

JavaScript

AdminUserCRUDController

JavaScript

Result:

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement