[Form][DataMapper] Do not update form to data when form is read only
This commit is contained in:
parent
72b2f6984c
commit
47605f63e3
@ -77,7 +77,7 @@ class PropertyPathMapper implements DataMapperInterface
|
||||
|
||||
public function mapFormToData(FormInterface $form, &$data)
|
||||
{
|
||||
if ($form->getAttribute('property_path') !== null && $form->isSynchronized()) {
|
||||
if ($form->getAttribute('property_path') !== null && $form->isSynchronized() && !$form->isReadOnly()) {
|
||||
$propertyPath = $form->getAttribute('property_path');
|
||||
|
||||
// If the data is identical to the value in $data, we are
|
||||
|
@ -34,7 +34,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
|
||||
$this->propertyPath = null;
|
||||
}
|
||||
|
||||
private function getForm(PropertyPath $propertyPath = null)
|
||||
private function getForm(PropertyPath $propertyPath = null, $synchronized = true, $readOnly = false)
|
||||
{
|
||||
$form = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
|
||||
|
||||
@ -43,6 +43,14 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
|
||||
->with('property_path')
|
||||
->will($this->returnValue($propertyPath));
|
||||
|
||||
$form->expects($this->any())
|
||||
->method('isSynchronized')
|
||||
->will($this->returnValue($synchronized));
|
||||
|
||||
$form->expects($this->any())
|
||||
->method('isReadOnly')
|
||||
->will($this->returnValue($readOnly));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@ -87,4 +95,16 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->mapper->mapDataToForm(null, $form);
|
||||
}
|
||||
|
||||
public function testMapFormToDataIgnoresReadOnlyForm()
|
||||
{
|
||||
$data = new \stdClass();
|
||||
|
||||
$form = $this->getForm($this->propertyPath, true, true);
|
||||
|
||||
$this->propertyPath->expects($this->never())
|
||||
->method('setValue');
|
||||
|
||||
$this->mapper->mapFormToData($form, $data);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user