diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 0b9cdcf1bb76..1fc4d4588435 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -294,6 +294,20 @@ public function isReadOnly() return true; } + /** + * Set read only form status + * + * @param Boolean read only status + * + * @return Form The current form + */ + public function setReadOnly($readOnly = true) + { + $this->readOnly = (Boolean) $readOnly; + + return $this; + } + /** * Sets the parent form. * @@ -370,6 +384,21 @@ public function getAttribute($name) return $this->attributes[$name]; } + /** + * Sets the value of the attributes with the given name. + * + * @param string $name The name of the attribute + * @param mixed $value The value of the attribute + * + * @return Form The current form + */ + public function setAttribute($name, $value) + { + $this->attributes[$name] = $value; + + return $this; + } + /** * Updates the field with default data. * diff --git a/tests/Symfony/Tests/Component/Form/FormTest.php b/tests/Symfony/Tests/Component/Form/FormTest.php index 4fbf6ff9b7b9..eb4ca3d86ff0 100644 --- a/tests/Symfony/Tests/Component/Form/FormTest.php +++ b/tests/Symfony/Tests/Component/Form/FormTest.php @@ -229,6 +229,24 @@ public function testNotReadOnly() $this->assertFalse($child->isReadOnly()); } + public function testSetReadOnlyAfterFormCreation() + { + $parent = $this->getBuilder()->setReadOnly(false)->getForm(); + + $parent->setReadOnly(true); + + $this->assertTrue($parent->isReadOnly()); + } + + public function testSetNotReadOnlyAfterFormCreation() + { + $parent = $this->getBuilder()->setReadOnly(true)->getForm(); + + $parent->setReadOnly(false); + + $this->assertFalse($parent->isReadOnly()); + } + public function testCloneChildren() { $child = $this->getBuilder('child')->getForm();