Преглед на файлове

Merge pull request #192 from stof/ajax_many_to_one

Ajax many to one
Thomas преди 14 години
родител
ревизия
5380abed16
променени са 3 файла, в които са добавени 20 реда и са изтрити 12 реда
  1. 18 10
      Controller/HelperController.php
  2. 1 1
      Resources/views/CRUD/edit_orm_many_to_one.html.twig
  3. 1 1
      Resources/views/CRUD/edit_orm_one_to_one.html.twig

+ 18 - 10
Controller/HelperController.php

@@ -30,11 +30,15 @@ class HelperController extends Controller
     {
         $helper     = $this->getAdminHelper();
         $request    = $this->get('request');
-        $code       = $request->get('code');
-        $elementId  = $request->get('elementId');
-        $objectId   = $request->get('objectId');
+        $code       = $request->query->get('code');
+        $elementId  = $request->query->get('elementId');
+        $objectId   = $request->query->get('objectId');
+        $uniqid     = $this->get('request')->query->get('uniqid');
 
         $admin = $helper->getAdmin($code);
+        if ($uniqid) {
+            $admin->setUniqid($uniqid);
+        }
 
         $subject = $admin->getModelManager()->findOne($admin->getClass(), $objectId);
         if (!$subject) {
@@ -58,15 +62,19 @@ class HelperController extends Controller
     public function retrieveFormFieldElementAction()
     {
         $helper     = $this->getAdminHelper();
-        $code       = $this->get('request')->get('code');
-        $elementId  = $this->get('request')->get('elementId');
-        $objectId   = $this->get('request')->get('objectId');
+        $code       = $this->get('request')->query->get('code');
+        $elementId  = $this->get('request')->query->get('elementId');
+        $objectId   = $this->get('request')->query->get('objectId');
         $admin      = $helper->getAdmin($code);
+        $uniqid     = $this->get('request')->query->get('uniqid');
 
         $subject = $admin->getModelManager()->findOne($admin->getClass(), $objectId);
         if (!$subject) {
             throw new NotFoundHttpException(sprintf('Unable to find the object id: %s, class: %s', $objectId, $admin->getClass()));
         }
+        if ($uniqid) {
+            $admin->setUniqid($uniqid);
+        }
 
         $formBuilder = $admin->getFormBuilder($subject);
 
@@ -84,11 +92,11 @@ class HelperController extends Controller
         return new Response($extension->renderWidget($childFormBuilder->getForm()->createView()));
     }
 
-    public function getShortObjectDescriptionAction($code = null, $objectId = null, $uniqid = null)
+    public function getShortObjectDescriptionAction()
     {
-        $code       = $code     ?: $this->get('request')->query->get('code');
-        $objectId   = $objectId ?: $this->get('request')->query->get('objectId');
-        $uniqid     = $uniqid   ?: $this->get('request')->get('uniqid');
+        $code       = $this->get('request')->query->get('code');
+        $objectId   = $this->get('request')->query->get('objectId');
+        $uniqid     = $this->get('request')->query->get('uniqid');
 
         $admin  = $this->container->get('sonata.admin.pool')->getInstance($code);
         if ($uniqid) {

+ 1 - 1
Resources/views/CRUD/edit_orm_many_to_one.html.twig

@@ -27,7 +27,7 @@ file that was distributed with this source code.
             {% if field_description.options.edit == 'list' %}
                 <span id="field_widget_{{ field_element.vars.id }}" >
                     {% if admin.id(value) %}
-                        {% render 'SonataAdminBundle:Helper:getShortObjectDescription' with {
+                        {% render 'SonataAdminBundle:Helper:getShortObjectDescription' with {}, {
                             'code': field_description.associationadmin.code,
                             'objectId': admin.id(value),
                             'uniqid':  field_description.associationadmin.uniqid

+ 1 - 1
Resources/views/CRUD/edit_orm_one_to_one.html.twig

@@ -26,7 +26,7 @@ file that was distributed with this source code.
             {% if field_description.options.edit == 'list' %}
                 <span id="field_widget_{{ field_element.vars.id }}" >
                     {% if admin.id(value) %}
-                        {% render 'SonataAdminBundle:Helper:getShortObjectDescription' with {
+                        {% render 'SonataAdminBundle:Helper:getShortObjectDescription' with {}, {
                             'code': field_description.associationadmin.code,
                             'objectId': admin.id(value),
                             'uniqid':  field_description.associationadmin.uniqid