-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add listener when try to remove a data that is related with other entity #7759
Comments
Can you give us more details about this exception. Because we're already catching Which is supposed to be thrown here: https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/4.x/src/Model/ModelManager.php#L96-L108 If we add custom logic, it won't be on sonata admin but on sonataDoctrineORMAdminBundle, since |
Hey @VincentLanglet it's the exception
sonata packages
|
@eerison Ok, so it's already caught by Sonata: The error is caught here: https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/595960b96f6a3c234141ffa8bc4e8bb9ea1d15a9/src/Model/ModelManager.php#L102-L107 Then, it's handled here: SonataAdminBundle/src/Controller/CRUDController.php Lines 242 to 257 in 89cac16
The method handle throwable is here: https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/Controller/CRUDController.php#L1083-L1096 In debug, it throws the exception, but in production you just log the error so it will add a flash message "an error occured" with SonataAdminBundle/src/Controller/CRUDController.php Lines 174 to 177 in 89cac16
Maybe what could be change is the fact that the handleModelManagerThrowable could return a string instead of void.
Then you could do "If the previous exeption is a ForeignKeyConstraintViolationException" I use my custom message. WDYT ? |
Yeah can be, but should be good return something like "This "object" is related with others data." or something like this, because if the user see "an error occured" only, he won't know what is the problem! |
You think like a developer. An object or a relation is something talking to you. For some project the admin can be something usable by every one, even customers. So Sonata have to go with a generic message, and will let open the ability to override/change it. Do you want to make the Pr to allow handleModelManagerThrowable to return a string ? |
I see, well I'm working on admin V3, I can't do that now :/ |
I'm doing it in #7761 then. |
Add flash message for
ForeignKeyConstraintViolationException
When I try to remove a data that is related with other entity I'm getting an internal server error of
ForeignKeyConstraintViolationException
I was thinking to add a listener for this exception and add a flash message with the error!
do you see any problem it be into the sonata code or should it be into my code?
The text was updated successfully, but these errors were encountered: