8000 [Form] Fixed regression: bind(null) was not converted to an empty str… · symfony/symfony@6e4ed9e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e4ed9e

Browse files
committed
[Form] Fixed regression: bind(null) was not converted to an empty string anymore
1 parent fcb2227 commit 6e4ed9e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ public function getDefaultOptions()
179179
if ($form->hasChildren()) {
180180
return array();
181181
}
182-
};
183182

184-
return '';
183+
return '';
184+
};
185185
};
186186

187187
return array(

src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,22 @@ public function testBindWithEmptyDataStoresArrayIfNoClassAvailable()
344344
$this->assertSame(array('firstName' => 'Bernhard'), $form->getData());
345345
}
346346

347+
public function testBindWithEmptyDataPassesEmptyStringToTransformerIfNoChildren()
348+
{
349+
$form = $this->factory->createBuilder('form')
350+
->appendClientTransformer(new FixedDataTransformer(array(
351+
// required for the initial, internal setData(null)
352+
null => 'null',
353+
// required to test that bind(null) is converted to ''
354+
'empty' => '',
355+
)))
356+
->getForm();
357+
358+
$form->bind(null);
359+
360+
$this->assertSame('empty', $form->getData());
361+
}
362+
347363
public function testBindWithEmptyDataUsesEmptyDataOption()
348364
{
349365
$author = new Author();

0 commit comments

Comments
 (0)
0