8000 [Form] Fixed: The "data" option is taken into account even if it is NULL · symfony/symfony@c1a3eb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1a3eb3

Browse files
committed
[Form] Fixed: The "data" option is taken into account even if it is NULL
1 parent 6fcb060 commit c1a3eb3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null)
4040
*/
4141
public function buildForm(FormBuilderInterface $builder, array $options)
4242
{
43+
$isDataOptionSet = array_key_exists('data', $options);
44+
4345
$builder
4446
->setRequired($options['required'])
4547
->setDisabled($options['disabled'])
@@ -51,8 +53,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5153
->setByReference($options['by_reference'])
5254
->setVirtual($options['virtual'])
5355
->setCompound($options['compound'])
54-
->setData(isset($options['data']) ? $options['data'] : null)
55-
->setDataLocked(isset($options['data']))
56+
->setData($isDataOptionSet ? $options['data'] : null)
57+
->setDataLocked($isDataOptionSet)
5658
->setDataMapper($options['compound'] ? new PropertyPathMapper($this->propertyAccessor) : null)
5759
;
5860

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,18 @@ public function testDataOptionSupersedesSetDataCalls()
650650
$this->assertSame('default', $form->getData());
651651
}
652652

653+
public function testDataOptionSupersedesSetDataCallsIfNull()
654+
{
655+
$form = $this->factory->create('form', null, array(
656+
'data' => null,
657+
'compound' => false,
658+
));
659+
660+
$form->setData('foobar');
661+
662+
$this->assertNull($form->getData());
663+
}
664+
653665
public function testNormDataIsPassedToView()
654666
{
655667
$view = $this->factory->createBuilder('form')

0 commit comments

Comments
 (0)
0