Skip to content

Commit

Permalink
merged branch bschussek/dataclassfix (PR #4374)
Browse files Browse the repository at this point in the history
Commits
-------

82c221a [Form] Fixed strict "data_class" check to work with instances of \ArrayAccess

Discussion
----------

[Form] Fixed collection type to work with recent Form changes

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

---------------------------------------------------------------------------

by tristanbes at 2012-05-22T16:42:36Z

Ping @fabpot Could you please merge it ASAP, because this bugs breaks all forms containing collection type.

Thanks

---------------------------------------------------------------------------

by travisbot at 2012-05-22T16:54:24Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1401580) (merged 82c221a into 1a1403f).
  • Loading branch information
fabpot committed May 22, 2012
2 parents 1a1403f + 82c221a commit e023807
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/Symfony/Component/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,8 @@ public function setData($appData)
if (!empty($clientData)) {
$dataClass = $this->config->getDataClass();

if (null === $dataClass && is_object($clientData)) {
$expectedType = 'scalar';

if (count($this->children) > 0 && $this->config->getDataMapper()) {
$expectedType = 'array';
}
if (null === $dataClass && is_object($clientData) && !$clientData instanceof \ArrayAccess) {
$expectedType = 'scalar, array or an instance of \ArrayAccess';

throw new FormException(
'The form\'s client data is expected to be of type ' . $expectedType . ', ' .
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Form/Tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,21 @@ public function testClientDataMustNotBeObjectIfDataClassIsNull()
$form->setData('foo');
}

public function testClientDataMayBeArrayAccessIfDataClassIsNull()
{
$arrayAccess = $this->getMock('\ArrayAccess');
$config = new FormConfig('name', null, $this->dispatcher);
$config->appendClientTransformer(new FixedDataTransformer(array(
'' => '',
'foo' => $arrayAccess,
)));
$form = new Form($config);

$form->setData('foo');

$this->assertSame($arrayAccess, $form->getClientData());
}

/**
* @expectedException Symfony\Component\Form\Exception\FormException
*/
Expand Down

0 comments on commit e023807

Please sign in to comment.