diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 0b9cdcf1bb76c..59638e3300be9 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -294,6 +294,20 @@ public function isReadOnly() return true; } + /** + * Sets whether this form is read only. + * + * @param Boolean + * + * @return Form The current form + */ + public function setReadOnly($readOnly) + { + $this->readOnly = (Boolean) $readOnly; + + return $this; + } + /** * Sets the parent form. * diff --git a/tests/Symfony/Tests/Component/Form/FormTest.php b/tests/Symfony/Tests/Component/Form/FormTest.php index 4fbf6ff9b7b9c..4f901d933dfc3 100644 --- a/tests/Symfony/Tests/Component/Form/FormTest.php +++ b/tests/Symfony/Tests/Component/Form/FormTest.php @@ -229,6 +229,18 @@ public function testNotReadOnly() $this->assertFalse($child->isReadOnly()); } + public function testSetReadOnly() + { + $form = $this->getBuilder()->getForm(); + $this->assertFalse($form->isReadOnly()); + + $form->setReadOnly(true); + $this->assertTrue($form->isReadOnly()); + + $form->setReadOnly(false); + $this->assertFalse($form->isReadOnly()); + } + public function testCloneChildren() { $child = $this->getBuilder('child')->getForm();