diff --git a/src/Symfony/Components/Form/Field.php b/src/Symfony/Components/Form/Field.php index 5da5d0e9f85d..0876e0f45b3e 100644 --- a/src/Symfony/Components/Form/Field.php +++ b/src/Symfony/Components/Form/Field.php @@ -42,9 +42,12 @@ public function __construct($key, array $options = array()) $this->addOption('property_path', (string)$key); $this->key = (string)$key; - $this->locale = class_exists('\Locale', false) ? \Locale::getDefault() : 'en'; $this->generator = new HtmlGenerator(); + if ($this->locale === null) { + $this->locale = class_exists('\Locale', false) ? \Locale::getDefault() : 'en'; + } + parent::__construct($options); $this->transformedData = $this->transform($this->data); diff --git a/src/Symfony/Components/Form/Form.php b/src/Symfony/Components/Form/Form.php index 8d7a9dd017da..35c61a7794c8 100644 --- a/src/Symfony/Components/Form/Form.php +++ b/src/Symfony/Components/Form/Form.php @@ -58,8 +58,6 @@ public function __construct($name, $object, ValidatorInterface $validator, array $this->generator = new HtmlGenerator(); $this->validator = $validator; - parent::__construct($name, $options); - $this->setData($object); $this->setCsrfFieldName(self::$defaultCsrfFieldName); @@ -80,6 +78,8 @@ public function __construct($name, $object, ValidatorInterface $validator, array if (self::$defaultTranslator !== null) { $this->setTranslator(self::$defaultTranslator); } + + parent::__construct($name, $options); } /** diff --git a/tests/Symfony/Tests/Components/Form/FormTest.php b/tests/Symfony/Tests/Components/Form/FormTest.php index 801c4d078053..da1bcc310135 100644 --- a/tests/Symfony/Tests/Components/Form/FormTest.php +++ b/tests/Symfony/Tests/Components/Form/FormTest.php @@ -25,6 +25,25 @@ protected function configure() } } +class TestSetDataBeforeConfigureForm extends Form +{ + protected $testCase; + protected $object; + + public function __construct($testCase, $name, $object, $validator) + { + $this->testCase = $testCase; + $this->object = $object; + + parent::__construct($name, $object, $validator); + } + + protected function configure() + { + $this->testCase->assertEquals($this->object, $this->getData()); + } +} + class FormTest extends \PHPUnit_Framework_TestCase { protected $validator; @@ -43,6 +62,11 @@ public function testConstructInitializesObject() $this->assertEquals(new Author(), $this->form->getData()); } + public function testSetDataBeforeConfigure() + { + new TestSetDataBeforeConfigureForm($this, 'author', new Author(), $this->validator); + } + public function testIsCsrfProtected() { $this->assertFalse($this->form->isCsrfProtected());