[Form] Fixed: "by_reference" option is ignored if reading from/writing to an array
This commit is contained in:
parent
59bf50bf41
commit
09a50c3c55
@ -895,7 +895,7 @@ class Form extends Field implements \IteratorAggregate, FormInterface
|
||||
// Don't update parent if data is a composite type (object or array)
|
||||
// and "by_reference" option is true, because then we expect that
|
||||
// we are working with a reference to the parent's data
|
||||
if (!is_object($data) || !$this->getOption('by_reference')) {
|
||||
if (!is_object($data) || !is_object($objectOrArray) || !$this->getOption('by_reference')) {
|
||||
parent::writeProperty($objectOrArray);
|
||||
}
|
||||
}
|
||||
|
@ -1258,6 +1258,29 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('foobar', $author->getReferenceCopy());
|
||||
}
|
||||
|
||||
public function testSubformAlwaysInsertsIntoArrays()
|
||||
{
|
||||
$ref1 = new Author();
|
||||
$ref2 = new Author();
|
||||
$author = array('referenceCopy' => $ref1);
|
||||
|
||||
$form = new Form('author', array('validator' => $this->createMockValidator()));
|
||||
$form->setData($author);
|
||||
$refForm = new FormTest_FormThatReturns('referenceCopy');
|
||||
$refForm->setReturnValue($ref2);
|
||||
$form->add($refForm);
|
||||
|
||||
$form->bind($this->createPostRequest(array(
|
||||
'author' => array(
|
||||
'referenceCopy' => array(), // doesn't matter actually
|
||||
)
|
||||
)));
|
||||
|
||||
// the new reference was inserted into the array
|
||||
$author = $form->getData();
|
||||
$this->assertSame($ref2, $author['referenceCopy']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a group containing two fields, "visibleField" and "hiddenField"
|
||||
*
|
||||
|
Reference in New Issue
Block a user