diff --git a/src/Symfony/Component/Form/Button.php b/src/Symfony/Component/Form/Button.php index 6961dd8d7890..8c5247d45f80 100644 --- a/src/Symfony/Component/Form/Button.php +++ b/src/Symfony/Component/Form/Button.php @@ -358,13 +358,14 @@ public function handleRequest($request = null) /** * Submits data to the button. * - * @param null|string $submittedData The data + * @param null|string $submittedData The data. + * @param Boolean $clearMissing Not used. * * @return Button The button instance * * @throws Exception\AlreadySubmittedException If the button has already been submitted. */ - public function submit($submittedData) + public function submit($submittedData, $clearMissing = true) { if ($this->submitted) { throw new AlreadySubmittedException('A form can only be submitted once'); diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index c0fc6d06de17..9a9f577a9be8 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -24,6 +24,7 @@ CHANGELOG * added methods submit() and isSubmitted() to Form * deprecated bind() and isBound() in Form * deprecated AlreadyBoundException in favor of AlreadySubmittedException + * added support for PATCH requests 2.2.0 ----- diff --git a/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php b/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php index 6457de747709..dcb6ede2b32d 100644 --- a/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php +++ b/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php @@ -75,6 +75,6 @@ public function handleRequest(FormInterface $form, $request = null) return; } - $form->submit($data); + $form->submit($data, 'PATCH' !== $method); } } diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 9ad47905ad8d..974168a9a7c5 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -464,7 +464,7 @@ public function handleRequest($request = null) /** * {@inheritdoc} */ - public function submit($submittedData) + public function submit($submittedData, $clearMissing = true) { if ($this->submitted) { throw new AlreadySubmittedException('A form can only be submitted once'); @@ -518,8 +518,10 @@ public function submit($submittedData) } foreach ($this->children as $name => $child) { - $child->submit(isset($submittedData[$name]) ? $submittedData[$name] : null); - unset($submittedData[$name]); + if (isset($submittedData[$name]) || $clearMissing) { + $child->submit(isset($submittedData[$name]) ? $submittedData[$name] : null, $clearMissing); + unset($submittedData[$name]); + } } $this->extraData = $submittedData; diff --git a/src/Symfony/Component/Form/FormInterface.php b/src/Symfony/Component/Form/FormInterface.php index 1069398ba8ee..1e35f788cb54 100644 --- a/src/Symfony/Component/Form/FormInterface.php +++ b/src/Symfony/Component/Form/FormInterface.php @@ -242,13 +242,16 @@ public function handleRequest($request = null); /** * Submits data to the form, transforms and validates it. * - * @param null|string|array $submittedData The submitted data. + * @param null|string|array $submittedData The submitted data. + * @param Boolean $clearMissing Whether to set fields to NULL + * when they are missing in the + * submitted data. * * @return FormInterface The form instance * * @throws Exception\AlreadySubmittedException If the form has already been submitted. */ - public function submit($submittedData); + public function submit($submittedData, $clearMissing = true); /** * Returns the root of the form tree. diff --git a/src/Symfony/Component/Form/NativeRequestHandler.php b/src/Symfony/Component/Form/NativeRequestHandler.php index 6ddb8d72a340..aaa4e4c0f23a 100644 --- a/src/Symfony/Component/Form/NativeRequestHandler.php +++ b/src/Symfony/Component/Form/NativeRequestHandler.php @@ -90,7 +90,7 @@ public function handleRequest(FormInterface $form, $request = null) return; } - $form->submit($data); + $form->submit($data, 'PATCH' !== $method); } /** diff --git a/src/Symfony/Component/Form/SubmitButton.php b/src/Symfony/Component/Form/SubmitButton.php index a169ba6529f7..47d4be0e28b4 100644 --- a/src/Symfony/Component/Form/SubmitButton.php +++ b/src/Symfony/Component/Form/SubmitButton.php @@ -34,15 +34,16 @@ public function isClicked() /** * Submits data to the button. * - * @param null|string $submittedData The data + * @param null|string $submittedData The data. + * @param Boolean $clearMissing Not used. * * @return SubmitButton The button instance * * @throws Exception\AlreadySubmittedException If the form has already been submitted. */ - public function submit($submittedData) + public function submit($submittedData, $clearMissing = true) { - parent::submit($submittedData); + parent::submit($submittedData, $clearMissing); $this->clicked = null !== $submittedData; diff --git a/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php b/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php index 1890ec00aaf8..cef8f3bf0d24 100644 --- a/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php @@ -58,8 +58,8 @@ public function testSubmitIfNameInRequest($method) )); $form->expects($this->once()) - ->method('Submit') - ->with('DATA'); + ->method('submit') + ->with('DATA', 'PATCH' !== $method); $this->requestHandler->handleRequest($form, $this->request); } @@ -78,7 +78,7 @@ public function testDoNotSubmitIfWrongRequestMethod($method) )); $form->expects($this->never()) - ->method('Submit'); + ->method('submit'); $this->requestHandler->handleRequest($form, $this->request); } @@ -95,8 +95,8 @@ public function testSubmitSimpleFormWithNullIfNameNotInRequestAndNotGetRequest($ )); $form->expects($this->once()) - ->method('Submit') - ->with($this->identicalTo(null)); + ->method('submit') + ->with($this->identicalTo(null), 'PATCH' !== $method); $this->requestHandler->handleRequest($form, $this->request); } @@ -113,8 +113,8 @@ public function testSubmitCompoundFormWithArrayIfNameNotInRequestAndNotGetReques )); $form->expects($this->once()) - ->method('Submit') - ->with($this->identicalTo(array())); + ->method('submit') + ->with($this->identicalTo(array()), 'PATCH' !== $method); $this->requestHandler->handleRequest($form, $this->request); } @@ -128,7 +128,7 @@ public function testDoNotSubmitIfNameNotInRequestAndGetRequest() )); $form->expects($this->never()) - ->method('Submit'); + ->method('submit'); $this->requestHandler->handleRequest($form, $this->request); } @@ -152,8 +152,8 @@ public function testSubmitFormWithEmptyNameIfAtLeastOneFieldInRequest($method) )); $form->expects($this->once()) - ->method('Submit') - ->with($requestData); + ->method('submit') + ->with($requestData, 'PATCH' !== $method); $this->requestHandler->handleRequest($form, $this->request); } @@ -176,7 +176,7 @@ public function testDoNotSubmitFormWithEmptyNameIfNoFieldInRequest($method) )); $form->expects($this->never()) - ->method('Submit'); + ->method('submit'); $this->requestHandler->handleRequest($form, $this->request); } @@ -200,11 +200,11 @@ public function testMergeParamsAndFiles($method) )); $form->expects($this->once()) - ->method('Submit') + ->method('submit') ->with(array( 'field1' => 'DATA', 'field2' => $file, - )); + ), 'PATCH' !== $method); $this->requestHandler->handleRequest($form, $this->request); } @@ -224,8 +224,8 @@ public function testParamTakesPrecedenceOverFile($method) )); $form->expects($this->once()) - ->method('Submit') - ->with('DATA'); + ->method('submit') + ->with('DATA', 'PATCH' !== $method); $this->requestHandler->handleRequest($form, $this->request); } @@ -245,8 +245,8 @@ public function testSubmitFileIfNoParam($method) )); $form->expects($this->once()) - ->method('Submit') - ->with($file); + ->method('submit') + ->with($file, 'PATCH' !== $method); $this->requestHandler->handleRequest($form, $this->request); } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index f213db3126c1..fdd1a0e9b7f8 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -58,6 +58,31 @@ public function testSubmitForwardsNullIfValueIsMissing() $this->form->submit(array()); } + public function testSubmitDoesNotForwardNullIfNotClearMissing() + { + $child = $this->getMockForm('firstName'); + + $this->form->add($child); + + $child->expects($this->never()) + ->method('submit'); + + $this->form->submit(array(), false); + } + + public function testClearMissingFlagIsForwarded() + { + $child = $this->getMockForm('firstName'); + + $this->form->add($child); + + $child->expects($this->once()) + ->method('submit') + ->with($this->equalTo('foo'), false); + + $this->form->submit(array('firstName' => 'foo'), false); + } + public function testCloneChildren() { $child = $this->getBuilder('child')->getForm(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy