Skip to content

Commit

Permalink
[Form] Fixed: The "data" option is taken into account even if it is NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed Oct 28, 2013
1 parent 6fcb060 commit c1a3eb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/FormType.php
Expand Up @@ -40,6 +40,8 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null)
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$isDataOptionSet = array_key_exists('data', $options);

$builder
->setRequired($options['required'])
->setDisabled($options['disabled'])
Expand All @@ -51,8 +53,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->setByReference($options['by_reference'])
->setVirtual($options['virtual'])
->setCompound($options['compound'])
->setData(isset($options['data']) ? $options['data'] : null)
->setDataLocked(isset($options['data']))
->setData($isDataOptionSet ? $options['data'] : null)
->setDataLocked($isDataOptionSet)
->setDataMapper($options['compound'] ? new PropertyPathMapper($this->propertyAccessor) : null)
;

Expand Down
Expand Up @@ -650,6 +650,18 @@ public function testDataOptionSupersedesSetDataCalls()
$this->assertSame('default', $form->getData());
}

public function testDataOptionSupersedesSetDataCallsIfNull()
{
$form = $this->factory->create('form', null, array(
'data' => null,
'compound' => false,
));

$form->setData('foobar');

$this->assertNull($form->getData());
}

public function testNormDataIsPassedToView()
{
$view = $this->factory->createBuilder('form')
Expand Down

0 comments on commit c1a3eb3

Please sign in to comment.