Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f495410

Browse filesBrowse files
committed
[Form] Disabled view data validation if "data_class" is set to null
1 parent d1a50a2 commit f495410
Copy full SHA for f495410

File tree

2 files changed

+9
-19
lines changed
Filter options

2 files changed

+9
-19
lines changed

‎src/Symfony/Component/Form/Form.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Form.php
+4-14Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,21 +356,11 @@ public function setData($modelData)
356356
if (!FormUtil::isEmpty($viewData)) {
357357
$dataClass = $this->config->getDataClass();
358358

359-
$actualType = is_object($viewData) ? 'an instance of class '.get_class($viewData) : 'a(n) '.gettype($viewData);
360-
361-
if (null === $dataClass && is_object($viewData) && !$viewData instanceof \ArrayAccess) {
362-
$expectedType = 'scalar, array or an instance of \ArrayAccess';
363-
364-
throw new LogicException(
365-
'The form\'s view data is expected to be of type '.$expectedType.', '.
366-
'but is '.$actualType.'. You '.
367-
'can avoid this error by setting the "data_class" option to '.
368-
'"'.get_class($viewData).'" or by adding a view transformer '.
369-
'that transforms '.$actualType.' to '.$expectedType.'.'
370-
);
371-
}
372-
373359
if (null !== $dataClass && !$viewData instanceof $dataClass) {
360+
$actualType = is_object($viewData)
361+
? 'an instance of class '.get_class($viewData)
362+
: 'a(n) '.gettype($viewData);
363+
374364
throw new LogicException(
375365
'The form\'s view data is expected to be an instance of class '.
376366
$dataClass.', but is '.$actualType.'. You can avoid this error '.

‎src/Symfony/Component/Form/Tests/SimpleFormTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/SimpleFormTest.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,19 +840,19 @@ public function testGetPropertyPathDefaultsToIndexedNameIfDataClassOfFirstParent
840840
$this->assertEquals(new PropertyPath('[name]'), $form->getPropertyPath());
841841
}
842842

843-
/**
844-
* @expectedException \Symfony\Component\Form\Exception\LogicException
845-
*/
846-
public function testViewDataMustNotBeObjectIfDataClassIsNull()
843+
public function testViewDataMayBeObjectIfDataClassIsNull()
847844
{
845+
$object = new \stdClass();
848846
$config = new FormConfigBuilder('name', null, $this->dispatcher);
849847
$config->addViewTransformer(new FixedDataTransformer(array(
850848
'' => '',
851-
'foo' => new \stdClass(),
849+
'foo' => $object,
852850
)));
853851
$form = new Form($config);
854852

855853
$form->setData('foo');
854+
855+
$this->assertSame($object, $form->getViewData());
856856
}
857857

858858
public function testViewDataMayBeArrayAccessIfDataClassIsNull()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.