File tree 2 files changed +17
-6
lines changed
src/Symfony/Component/Form
2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -340,12 +340,8 @@ public function setData($appData)
340
340
if (!empty ($ clientData )) {
341
341
$ dataClass = $ this ->config ->getDataClass ();
342
342
343
- if (null === $ dataClass && is_object ($ clientData )) {
344
- $ expectedType = 'scalar ' ;
345
-
346
- if (count ($ this ->children ) > 0 && $ this ->config ->getDataMapper ()) {
347
- $ expectedType = 'array ' ;
348
- }
343
+ if (null === $ dataClass && is_object ($ clientData ) && !$ clientData instanceof \ArrayAccess) {
344
+ $ expectedType = 'scalar, array or an instance of \ArrayAccess ' ;
349
345
350
346
throw new FormException (
351
347
'The form \'s client data is expected to be of type ' . $ expectedType . ', ' .
Original file line number Diff line number Diff line change @@ -1249,6 +1249,21 @@ public function testClientDataMustNotBeObjectIfDataClassIsNull()
1249
1249
$ form ->setData ('foo ' );
1250
1250
}
1251
1251
1252
+ public function testClientDataMayBeArrayAccessIfDataClassIsNull ()
1253
+ {
1254
+ $ arrayAccess = $ this ->getMock ('\ArrayAccess ' );
1255
+ $ config = new FormConfig ('name ' , null , $ this ->dispatcher );
1256
+ $ config ->appendClientTransformer (new FixedDataTransformer (array (
1257
+ '' => '' ,
1258
+ 'foo ' => $ arrayAccess ,
1259
+ )));
1260
+ $ form = new Form ($ config );
1261
+
1262
+ $ form ->setData ('foo ' );
1263
+
1264
+ $ this ->assertSame ($ arrayAccess , $ form ->getClientData ());
1265
+ }
1266
+
1252
1267
/**
1253
1268
* @expectedException Symfony\Component\Form\Exception\FormException
1254
1269
*/
You can’t perform that action at this time.
0 commit comments