Просмотр исходного кода

Improve create and update process

Florent Denis 11 лет назад
Родитель
Сommit
34d3596c19
3 измененных файлов с 18 добавлено и 6 удалено
  1. 14 2
      Admin/Admin.php
  2. 2 2
      Controller/CRUDController.php
  3. 2 2
      Model/ModelManagerInterface.php

+ 14 - 2
Admin/Admin.php

@@ -611,12 +611,18 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             $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;
     }
 
     /**
@@ -629,7 +635,11 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             $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) {
@@ -637,6 +647,8 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         }
 
         $this->createObjectSecurity($object);
+
+        return $object;
     }
 
     /**

+ 2 - 2
Controller/CRUDController.php

@@ -317,7 +317,7 @@ class CRUDController extends Controller
 
             // 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(
@@ -530,7 +530,7 @@ class CRUDController extends Controller
                     throw new AccessDeniedException();
                 }
 
-                $this->admin->create($object);
+                $object = $this->admin->create($object);
 
                 if ($this->isXmlHttpRequest()) {
                     return $this->renderJson(array(

+ 2 - 2
Model/ModelManagerInterface.php

@@ -35,14 +35,14 @@ interface ModelManagerInterface
     /**
      * @param mixed $object
      *
-     * @return void
+     * @return mixed
      */
     public function create($object);
 
     /**
      * @param mixed $object
      *
-     * @return void
+     * @return mixed
      */
     public function update($object);