From c1a3eb3f2e082c9e9693421db7ed3e417080bc38 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 28 Oct 2013 10:50:26 +0100 Subject: [PATCH] [Form] Fixed: The "data" option is taken into account even if it is NULL --- .../Component/Form/Extension/Core/Type/FormType.php | 6 ++++-- .../Form/Tests/Extension/Core/Type/FormTypeTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index 8e089bd4d6f4..9232857b7741 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -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']) @@ -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) ; diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 2d0bf3045569..68e62e8bdabc 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -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')