Jelajahi Sumber

change method name preInsert => prePersist, add edit_file

Thomas 14 tahun lalu
induk
melakukan
59cef4349b
3 mengubah file dengan 87 tambahan dan 5 penghapusan
  1. 70 3
      Admin/Admin.php
  2. 3 2
      Controller/CRUDController.php
  3. 14 0
      Resources/views/CRUD/edit_file.html.twig

+ 70 - 3
Admin/Admin.php

@@ -365,12 +365,12 @@ abstract class Admin implements AdminInterface
 
     }
 
-    public function preInsert($object)
+    public function prePersist($object)
     {
 
     }
 
-    public function postInsert($object)
+    public function postPersist($object)
     {
 
     }
@@ -787,6 +787,9 @@ abstract class Admin implements AdminInterface
             $parameters['uniqid'] = $this->getUniqid();
             $parameters['code']   = $this->getCode();
         }
+
+        // allows to define persistent parameters 
+        $parameters = array_merge($this->getPersitentParameters(), $parameters);
         
         $url = $this->getUrl($name);
 
@@ -1466,10 +1469,19 @@ abstract class Admin implements AdminInterface
      */
     public function getClassnameLabel()
     {
-
         return $this->classnameLabel;
     }
 
+    /**
+     * return an array of persistent parameters
+     *
+     * @return array
+     */
+    public function getPersitentParameters()
+    {
+        return array();
+    }
+
     /**
      * generate the breadcrumbs array
      *
@@ -1607,16 +1619,26 @@ abstract class Admin implements AdminInterface
         return $this->translationDomain;
     }
 
+    /**
+     *
+     */
     public function setTranslator(TranslatorInterface $translator)
     {
         $this->translator = $translator;
     }
 
+    /**
+     * 
+     */
     public function getTranslator()
     {
         return $this->translator;
     }
 
+    /**
+     * @param \Symfony\Component\HttpFoundation\Request $request
+     * @return void
+     */
     public function setRequest(Request $request)
     {
         $this->request = $request;
@@ -1626,66 +1648,111 @@ abstract class Admin implements AdminInterface
         }
     }
 
+    /**
+     * @return Symfony\Component\HttpFoundation\Request
+     */
     public function getRequest()
     {
         return $this->request;
     }
 
+    /**
+     * @param \Sonata\AdminBundle\Builder\FormBuilderInterface $formBuilder
+     * @return void
+     */
     public function setFormBuilder(FormBuilderInterface $formBuilder)
     {
         $this->formBuilder = $formBuilder;
     }
 
+    /**
+     * @return Sonata\AdminBundle\Builder\FormBuilderInterface
+     */
     public function getFormBuilder()
     {
         return $this->formBuilder;
     }
 
+    /**
+     * @param \Sonata\AdminBundle\Builder\DatagridBuilderInterface $datagridBuilder
+     * @return void
+     */
     public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder)
     {
         $this->datagridBuilder = $datagridBuilder;
     }
 
+    /**
+     * @return Sonata\AdminBundle\Builder\DatagridBuilderInterface
+     */
     public function getDatagridBuilder()
     {
         return $this->datagridBuilder;
     }
 
+    /**
+     * @param \Sonata\AdminBundle\Builder\ListBuilderInterface $listBuilder
+     * @return void
+     */
     public function setListBuilder(ListBuilderInterface $listBuilder)
     {
         $this->listBuilder = $listBuilder;
     }
 
+    /**
+     * @return Sonata\AdminBundle\Builder\ListBuilderInterface
+     */
     public function getListBuilder()
     {
         return $this->listBuilder;
     }
 
+    /**
+     * @param Pool $configurationPool
+     * @return void
+     */
     public function setConfigurationPool(Pool $configurationPool)
     {
         $this->configurationPool = $configurationPool;
     }
 
+    /**
+     * @return Pool
+     */
     public function getConfigurationPool()
     {
         return $this->configurationPool;
     }
 
+    /**
+     * @param \Symfony\Component\Routing\RouterInterface $router
+     * @return void
+     */
     public function setRouter(RouterInterface $router)
     {
         $this->router = $router;
     }
 
+    /**
+     * @return Symfony\Component\Routing\RouterInterface
+     */
     public function getRouter()
     {
         return $this->router;
     }
 
+    /**
+     * @param  $modelManager
+     * @return void
+     */
     public function setModelManager($modelManager)
     {
         $this->modelManager = $modelManager;
     }
 
+    /**
+     * @return object
+     */
     public function getModelManager()
     {
         return $this->modelManager;

+ 3 - 2
Controller/CRUDController.php

@@ -241,7 +241,7 @@ class CRUDController extends Controller
         if ($form->isValid()) {
 
             if ($action == 'create') {
-                $this->admin->preInsert($object);
+                $this->admin->prePersist($object);
             } else {
                 $this->admin->preUpdate($object);
             }
@@ -250,7 +250,7 @@ class CRUDController extends Controller
             $this->admin->getModelManager()->flush($object);
 
             if ($action == 'create') {
-                $this->admin->postInsert($object);
+                $this->admin->postPersist($object);
             } else {
                 $this->admin->postUpdate($object);
             }
@@ -378,4 +378,5 @@ class CRUDController extends Controller
 
         return $this->admin->getBreadcrumbs($action);
     }
+
 }

+ 14 - 0
Resources/views/CRUD/edit_file.html.twig

@@ -0,0 +1,14 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+{% extends base_template %}
+
+{% block field %}{{ form_field(field_element, {'class' : 'title'}) }}{% endblock %}