Skip to content

Commit

Permalink
Improve create and update process
Browse files Browse the repository at this point in the history
  • Loading branch information
pokap committed Jul 9, 2014
1 parent bce1cd2 commit 34d3596
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
16 changes: 14 additions & 2 deletions Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,18 @@ public function update($object)
$extension->preUpdate($this, $object);
}

$this->getModelManager()->update($object);
$result = $this->getModelManager()->update($object);
// BC compatibility
if (null !== $result) {
$object = $result;
}

$this->postUpdate($object);
foreach ($this->extensions as $extension) {
$extension->postUpdate($this, $object);
}

return $object;
}

/**
Expand All @@ -629,14 +635,20 @@ public function create($object)
$extension->prePersist($this, $object);
}

$this->getModelManager()->create($object);
$result = $this->getModelManager()->create($object);
// BC compatibility
if (null !== $result) {
$object = $result;
}

$this->postPersist($object);
foreach ($this->extensions as $extension) {
$extension->postPersist($this, $object);
}

$this->createObjectSecurity($object);

return $object;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function editAction($id = null)

// persist if the form was valid and if in preview mode the preview was approved
if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
$this->admin->update($object);
$object = $this->admin->update($object);

if ($this->isXmlHttpRequest()) {
return $this->renderJson(array(
Expand Down Expand Up @@ -530,7 +530,7 @@ public function createAction()
throw new AccessDeniedException();
}

$this->admin->create($object);
$object = $this->admin->create($object);

if ($this->isXmlHttpRequest()) {
return $this->renderJson(array(
Expand Down
4 changes: 2 additions & 2 deletions Model/ModelManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public function getNewFieldDescriptionInstance($class, $name, array $options = a
/**
* @param mixed $object
*
* @return void
* @return mixed
*/
public function create($object);

/**
* @param mixed $object
*
* @return void
* @return mixed
*/
public function update($object);

Expand Down

0 comments on commit 34d3596

Please sign in to comment.