8000 [Form] Fixed: The "data" option is taken into account even if it is NULL by webmozart · Pull Request #9388 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Fixed: The "data" option is taken into account even if it is NULL #9388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/FormType.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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