|
@@ -236,43 +236,46 @@ class CRUDController extends Controller
|
|
|
$templateKey = 'edit';
|
|
|
|
|
|
$id = $request->get($this->admin->getIdParameter());
|
|
|
- $object = $this->admin->getObject($id);
|
|
|
+ $existingObject = $this->admin->getObject($id);
|
|
|
|
|
|
- if (!$object) {
|
|
|
+ if (!$existingObject) {
|
|
|
throw $this->createNotFoundException(sprintf('unable to find the object with id : %s', $id));
|
|
|
}
|
|
|
|
|
|
- $this->admin->checkAccess('edit', $object);
|
|
|
+ $this->admin->checkAccess('edit', $existingObject);
|
|
|
|
|
|
- $preResponse = $this->preEdit($request, $object);
|
|
|
+ $preResponse = $this->preEdit($request, $existingObject);
|
|
|
if ($preResponse !== null) {
|
|
|
return $preResponse;
|
|
|
}
|
|
|
|
|
|
- $this->admin->setSubject($object);
|
|
|
+ $this->admin->setSubject($existingObject);
|
|
|
|
|
|
/** @var $form Form */
|
|
|
$form = $this->admin->getForm();
|
|
|
- $form->setData($object);
|
|
|
+ $form->setData($existingObject);
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
if ($form->isSubmitted()) {
|
|
|
//TODO: remove this check for 4.0
|
|
|
if (method_exists($this->admin, 'preValidate')) {
|
|
|
- $this->admin->preValidate($object);
|
|
|
+ $this->admin->preValidate($existingObject);
|
|
|
}
|
|
|
$isFormValid = $form->isValid();
|
|
|
|
|
|
// persist if the form was valid and if in preview mode the preview was approved
|
|
|
if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
|
|
|
+ $submittedObject = $form->getData();
|
|
|
+ $this->admin->setSubject($submittedObject);
|
|
|
+
|
|
|
try {
|
|
|
- $object = $this->admin->update($object);
|
|
|
+ $existingObject = $this->admin->update($submittedObject);
|
|
|
|
|
|
if ($this->isXmlHttpRequest()) {
|
|
|
return $this->renderJson(array(
|
|
|
'result' => 'ok',
|
|
|
- 'objectId' => $this->admin->getNormalizedIdentifier($object),
|
|
|
- 'objectName' => $this->escapeHtml($this->admin->toString($object)),
|
|
|
+ 'objectId' => $this->admin->getNormalizedIdentifier($existingObject),
|
|
|
+ 'objectName' => $this->escapeHtml($this->admin->toString($existingObject)),
|
|
|
), 200, array());
|
|
|
}
|
|
|
|
|
@@ -280,21 +283,21 @@ class CRUDController extends Controller
|
|
|
'sonata_flash_success',
|
|
|
$this->trans(
|
|
|
'flash_edit_success',
|
|
|
- array('%name%' => $this->escapeHtml($this->admin->toString($object))),
|
|
|
+ array('%name%' => $this->escapeHtml($this->admin->toString($existingObject))),
|
|
|
'SonataAdminBundle'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
// redirect to edit mode
|
|
|
- return $this->redirectTo($object);
|
|
|
+ return $this->redirectTo($existingObject);
|
|
|
} catch (ModelManagerException $e) {
|
|
|
$this->handleModelManagerException($e);
|
|
|
|
|
|
$isFormValid = false;
|
|
|
} catch (LockException $e) {
|
|
|
$this->addFlash('sonata_flash_error', $this->trans('flash_lock_error', array(
|
|
|
- '%name%' => $this->escapeHtml($this->admin->toString($object)),
|
|
|
- '%link_start%' => '<a href="'.$this->admin->generateObjectUrl('edit', $object).'">',
|
|
|
+ '%name%' => $this->escapeHtml($this->admin->toString($existingObject)),
|
|
|
+ '%link_start%' => '<a href="'.$this->admin->generateObjectUrl('edit', $existingObject).'">',
|
|
|
'%link_end%' => '</a>',
|
|
|
), 'SonataAdminBundle'));
|
|
|
}
|
|
@@ -307,7 +310,7 @@ class CRUDController extends Controller
|
|
|
'sonata_flash_error',
|
|
|
$this->trans(
|
|
|
'flash_edit_error',
|
|
|
- array('%name%' => $this->escapeHtml($this->admin->toString($object))),
|
|
|
+ array('%name%' => $this->escapeHtml($this->admin->toString($existingObject))),
|
|
|
'SonataAdminBundle'
|
|
|
)
|
|
|
);
|
|
@@ -326,7 +329,7 @@ class CRUDController extends Controller
|
|
|
return $this->render($this->admin->getTemplate($templateKey), array(
|
|
|
'action' => 'edit',
|
|
|
'form' => $formView,
|
|
|
- 'object' => $object,
|
|
|
+ 'object' => $existingObject,
|
|
|
), null);
|
|
|
}
|
|
|
|
|
@@ -486,38 +489,40 @@ class CRUDController extends Controller
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- $object = $this->admin->getNewInstance();
|
|
|
+ $newObject = $this->admin->getNewInstance();
|
|
|
|
|
|
- $preResponse = $this->preCreate($request, $object);
|
|
|
+ $preResponse = $this->preCreate($request, $newObject);
|
|
|
if ($preResponse !== null) {
|
|
|
return $preResponse;
|
|
|
}
|
|
|
|
|
|
- $this->admin->setSubject($object);
|
|
|
+ $this->admin->setSubject($newObject);
|
|
|
|
|
|
/** @var $form \Symfony\Component\Form\Form */
|
|
|
$form = $this->admin->getForm();
|
|
|
- $form->setData($object);
|
|
|
+ $form->setData($newObject);
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
if ($form->isSubmitted()) {
|
|
|
//TODO: remove this check for 4.0
|
|
|
if (method_exists($this->admin, 'preValidate')) {
|
|
|
- $this->admin->preValidate($object);
|
|
|
+ $this->admin->preValidate($newObject);
|
|
|
}
|
|
|
$isFormValid = $form->isValid();
|
|
|
|
|
|
// persist if the form was valid and if in preview mode the preview was approved
|
|
|
if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
|
|
|
- $this->admin->checkAccess('create', $object);
|
|
|
+ $submittedObject = $form->getData();
|
|
|
+ $this->admin->setSubject($submittedObject);
|
|
|
+ $this->admin->checkAccess('create', $submittedObject);
|
|
|
|
|
|
try {
|
|
|
- $object = $this->admin->create($object);
|
|
|
+ $newObject = $this->admin->create($submittedObject);
|
|
|
|
|
|
if ($this->isXmlHttpRequest()) {
|
|
|
return $this->renderJson(array(
|
|
|
'result' => 'ok',
|
|
|
- 'objectId' => $this->admin->getNormalizedIdentifier($object),
|
|
|
+ 'objectId' => $this->admin->getNormalizedIdentifier($newObject),
|
|
|
), 200, array());
|
|
|
}
|
|
|
|
|
@@ -525,13 +530,13 @@ class CRUDController extends Controller
|
|
|
'sonata_flash_success',
|
|
|
$this->trans(
|
|
|
'flash_create_success',
|
|
|
- array('%name%' => $this->escapeHtml($this->admin->toString($object))),
|
|
|
+ array('%name%' => $this->escapeHtml($this->admin->toString($newObject))),
|
|
|
'SonataAdminBundle'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
// redirect to edit mode
|
|
|
- return $this->redirectTo($object);
|
|
|
+ return $this->redirectTo($newObject);
|
|
|
} catch (ModelManagerException $e) {
|
|
|
$this->handleModelManagerException($e);
|
|
|
|
|
@@ -546,7 +551,7 @@ class CRUDController extends Controller
|
|
|
'sonata_flash_error',
|
|
|
$this->trans(
|
|
|
'flash_create_error',
|
|
|
- array('%name%' => $this->escapeHtml($this->admin->toString($object))),
|
|
|
+ array('%name%' => $this->escapeHtml($this->admin->toString($newObject))),
|
|
|
'SonataAdminBundle'
|
|
|
)
|
|
|
);
|
|
@@ -565,7 +570,7 @@ class CRUDController extends Controller
|
|
|
return $this->render($this->admin->getTemplate($templateKey), array(
|
|
|
'action' => 'create',
|
|
|
'form' => $formView,
|
|
|
- 'object' => $object,
|
|
|
+ 'object' => $newObject,
|
|
|
), null);
|
|
|
}
|
|
|
|