Pārlūkot izejas kodu

Fix deprecated Form::submit usage

Sullivan SENECHAL 10 gadi atpakaļ
vecāks
revīzija
8333f84d54

+ 1 - 1
Admin/AdminHelper.php

@@ -106,7 +106,7 @@ class AdminHelper
 
         $form = $formBuilder->getForm();
         $form->setData($subject);
-        $form->submit($admin->getRequest());
+        $form->handleRequest($admin->getRequest());
 
         // get the field element
         $childFormBuilder = $this->getChildFormBuilder($formBuilder, $elementId);

+ 5 - 7
Controller/CRUDController.php

@@ -415,10 +415,9 @@ class CRUDController extends Controller
         /** @var $form \Symfony\Component\Form\Form */
         $form = $this->admin->getForm();
         $form->setData($object);
+        $form->handleRequest($request);
 
-        if ($this->getRestMethod($request) === 'POST') {
-            $form->submit($request);
-
+        if ($form->isSubmitted()) {
             $isFormValid = $form->isValid();
 
             // persist if the form was valid and if in preview mode the preview was approved
@@ -682,10 +681,9 @@ class CRUDController extends Controller
         /** @var $form \Symfony\Component\Form\Form */
         $form = $this->admin->getForm();
         $form->setData($object);
+        $form->handleRequest($request);
 
-        if ($this->getRestMethod($request) === 'POST') {
-            $form->submit($request);
-
+        if ($form->isSubmitted()) {
             $isFormValid = $form->isValid();
 
             // persist if the form was valid and if in preview mode the preview was approved
@@ -1205,7 +1203,7 @@ class CRUDController extends Controller
             }
 
             if (isset($form)) {
-                $form->submit($request);
+                $form->handleRequest($request);
 
                 if ($form->isValid()) {
                     $adminObjectAclManipulator->$updateMethod($adminObjectAclData);

+ 1 - 1
Controller/HelperController.php

@@ -148,7 +148,7 @@ class HelperController
         $formBuilder = $admin->getFormBuilder($subject);
 
         $form = $formBuilder->getForm();
-        $form->submit($request);
+        $form->handleRequest($request);
 
         $view = $this->helper->getChildFormView($form->createView(), $elementId);
 

+ 44 - 0
Tests/Controller/CRUDControllerTest.php

@@ -1411,6 +1411,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(true));
@@ -1455,6 +1459,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(false));
@@ -1513,6 +1521,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(true));
@@ -1553,6 +1565,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(false));
@@ -1669,6 +1685,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('createView')
             ->will($this->returnValue($formView));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(true));
@@ -1810,6 +1830,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(true));
@@ -1865,6 +1889,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(true));
@@ -1902,6 +1930,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(false));
@@ -2028,6 +2060,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(true));
@@ -2076,6 +2112,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getForm')
             ->will($this->returnValue($form));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(false));
@@ -2138,6 +2178,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('createView')
             ->will($this->returnValue($formView));
 
+        $form->expects($this->once())
+            ->method('isSubmitted')
+            ->will($this->returnValue(true));
+
         $form->expects($this->once())
             ->method('isValid')
             ->will($this->returnValue(true));