Revert "[Form] Fix of "PATCH'ed forms are never valid""
This reverts commit a2b15359d8
.
Conflicts:
src/Symfony/Component/Form/Form.php
The commit is reverted because it introduces a bug demonstrated by a currently failing test.
This commit is contained in:
parent
bd30a5cc30
commit
50f201ec64
@ -500,14 +500,6 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
// In order to process patch requests we need to "submit" null values
|
||||
// Later this value will be mapped via DataMapper and InheritDataAwareIterator
|
||||
if ($submittedData === null && !$clearMissing) {
|
||||
$this->submitted = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// The data must be initialized if it was not initialized yet.
|
||||
// This is necessary to guarantee that the *_SET_DATA listeners
|
||||
// are always invoked before submit() takes place.
|
||||
@ -545,12 +537,10 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
}
|
||||
|
||||
foreach ($this->children as $name => $child) {
|
||||
$fieldValue = null;
|
||||
if (array_key_exists($name, $submittedData)) {
|
||||
$fieldValue = $submittedData[$name];
|
||||
if (array_key_exists($name, $submittedData) || $clearMissing) {
|
||||
$child->submit(isset($submittedData[$name]) ? $submittedData[$name] : null, $clearMissing);
|
||||
unset($submittedData[$name]);
|
||||
}
|
||||
$child->submit($fieldValue, $clearMissing);
|
||||
}
|
||||
|
||||
$this->extraData = $submittedData;
|
||||
|
@ -59,17 +59,14 @@ class CompoundFormTest extends AbstractFormTest
|
||||
$this->form->submit(array());
|
||||
}
|
||||
|
||||
public function testSubmitDoesNotSaveNullIfNotClearMissing()
|
||||
public function testSubmitDoesNotForwardNullIfNotClearMissing()
|
||||
{
|
||||
$child = $this->getMockForm('firstName');
|
||||
|
||||
$this->form->add($child);
|
||||
|
||||
$child->expects($this->once())
|
||||
->method('submit');
|
||||
|
||||
$child->expects($this->never())
|
||||
->method('setData');
|
||||
->method('submit');
|
||||
|
||||
$this->form->submit(array(), false);
|
||||
}
|
||||
@ -564,74 +561,6 @@ class CompoundFormTest extends AbstractFormTest
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
public function testSubmitPatchRequest()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
|
||||
$this->markTestSkipped('The "HttpFoundation" component is not available');
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->name = 'Bernhard';
|
||||
$object->name2 = 'Me';
|
||||
|
||||
//$values = array();
|
||||
$values = array(
|
||||
'author' => array(
|
||||
'name2' => 'Artem',
|
||||
),
|
||||
);
|
||||
|
||||
$request = new Request(array(), $values, array(), array(), array(), array(
|
||||
'REQUEST_METHOD' => 'PATCH',
|
||||
));
|
||||
|
||||
$mapper = $this->getDataMapper();
|
||||
$mapper->expects($this->any())
|
||||
->method('mapDataToForms')
|
||||
->will($this->returnCallback(function($data, $forms){
|
||||
foreach ($forms as $form) {
|
||||
$propertyPath = $form->getPropertyPath();
|
||||
|
||||
if (null !== $propertyPath) {
|
||||
$form->setData($data->{$propertyPath});
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
$mapper->expects($this->any())
|
||||
->method('mapFormsToData')
|
||||
->will($this->returnCallback(function($forms, &$data){
|
||||
foreach ($forms as $form) {
|
||||
$propertyPath = $form->getPropertyPath();
|
||||
|
||||
if (null !== $propertyPath) {
|
||||
if (!is_object($data) || $form->getData() !== $data->{$propertyPath}) {
|
||||
$data->{$propertyPath} = $form->getData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
/** @var Form $form */
|
||||
$form = $this->getBuilder('author', null, 'stdClass')
|
||||
->setMethod('PATCH')
|
||||
->setData($object)
|
||||
->setCompound(true)
|
||||
->setDataMapper($mapper)
|
||||
->setRequestHandler(new HttpFoundationRequestHandler())
|
||||
->getForm();
|
||||
$form->add($this->getBuilder('name')->getForm());
|
||||
$form->add($this->getBuilder('name2')->getForm());
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
$this->assertTrue($form->isValid());
|
||||
|
||||
$this->assertEquals('Bernhard', $form['name']->getData());
|
||||
$this->assertEquals('Artem', $form['name2']->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider requestMethodProvider
|
||||
*/
|
||||
|
Reference in New Issue
Block a user