merged branch bschussek/dataclassfix (PR #4374)
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) (merged82c221a1
into1a1403f5
).
This commit is contained in:
commit
e0238071d4
@ -340,12 +340,8 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
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 . ', ' .
|
||||
|
@ -1249,6 +1249,21 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
$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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user