|
@@ -318,19 +318,26 @@ class CRUDController extends Controller
|
|
|
|
|
|
// persist if the form was valid and if in preview mode the preview was approved
|
|
// persist if the form was valid and if in preview mode the preview was approved
|
|
if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
|
|
if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
|
|
- $object = $this->admin->update($object);
|
|
|
|
|
|
|
|
- if ($this->isXmlHttpRequest()) {
|
|
|
|
- return $this->renderJson(array(
|
|
|
|
- 'result' => 'ok',
|
|
|
|
- 'objectId' => $this->admin->getNormalizedIdentifier($object)
|
|
|
|
- ));
|
|
|
|
- }
|
|
|
|
|
|
+ try {
|
|
|
|
+ $object = $this->admin->update($object);
|
|
|
|
+
|
|
|
|
+ if ($this->isXmlHttpRequest()) {
|
|
|
|
+ return $this->renderJson(array(
|
|
|
|
+ 'result' => 'ok',
|
|
|
|
+ 'objectId' => $this->admin->getNormalizedIdentifier($object)
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
|
|
- $this->addFlash('sonata_flash_success', $this->admin->trans('flash_edit_success', array('%name%' => $this->admin->toString($object)), 'SonataAdminBundle'));
|
|
|
|
|
|
+ $this->addFlash('sonata_flash_success', $this->admin->trans('flash_edit_success', array('%name%' => $this->admin->toString($object)), 'SonataAdminBundle'));
|
|
|
|
|
|
- // redirect to edit mode
|
|
|
|
- return $this->redirectTo($object);
|
|
|
|
|
|
+ // redirect to edit mode
|
|
|
|
+ return $this->redirectTo($object);
|
|
|
|
+
|
|
|
|
+ } catch (ModelManagerException $e) {
|
|
|
|
+
|
|
|
|
+ $isFormValid = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// show an error message if the form failed validation
|
|
// show an error message if the form failed validation
|
|
@@ -534,19 +541,25 @@ class CRUDController extends Controller
|
|
throw new AccessDeniedException();
|
|
throw new AccessDeniedException();
|
|
}
|
|
}
|
|
|
|
|
|
- $object = $this->admin->create($object);
|
|
|
|
|
|
+ try {
|
|
|
|
+ $object = $this->admin->create($object);
|
|
|
|
|
|
- if ($this->isXmlHttpRequest()) {
|
|
|
|
- return $this->renderJson(array(
|
|
|
|
- 'result' => 'ok',
|
|
|
|
- 'objectId' => $this->admin->getNormalizedIdentifier($object)
|
|
|
|
- ));
|
|
|
|
- }
|
|
|
|
|
|
+ if ($this->isXmlHttpRequest()) {
|
|
|
|
+ return $this->renderJson(array(
|
|
|
|
+ 'result' => 'ok',
|
|
|
|
+ 'objectId' => $this->admin->getNormalizedIdentifier($object)
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->addFlash('sonata_flash_success', $this->admin->trans('flash_create_success', array('%name%' => $this->admin->toString($object)), 'SonataAdminBundle'));
|
|
|
|
|
|
- $this->addFlash('sonata_flash_success', $this->admin->trans('flash_create_success', array('%name%' => $this->admin->toString($object)), 'SonataAdminBundle'));
|
|
|
|
|
|
+ // redirect to edit mode
|
|
|
|
+ return $this->redirectTo($object);
|
|
|
|
|
|
- // redirect to edit mode
|
|
|
|
- return $this->redirectTo($object);
|
|
|
|
|
|
+ } catch (ModelManagerException $e) {
|
|
|
|
+
|
|
|
|
+ $isFormValid = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// show an error message if the form failed validation
|
|
// show an error message if the form failed validation
|