diff --git a/src/Symfony/Component/Form/FieldGroup.php b/src/Symfony/Component/Form/FieldGroup.php index 4bb11a710e..b2b86b71e6 100644 --- a/src/Symfony/Component/Form/FieldGroup.php +++ b/src/Symfony/Component/Form/FieldGroup.php @@ -332,6 +332,8 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac } } + $taintedData = $this->preprocessData($taintedData); + foreach ($taintedData as $key => $value) { if ($this->has($key)) { $this->fields[$key]->bind($value); @@ -358,6 +360,19 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac } } + /** + * Processes the bound data before it is passed to the individual fields + * + * The data is in the user format. + * + * @param array $data + * @return array + */ + protected function preprocessData(array $data) + { + return $data; + } + /** * Returns whether this form was bound with extra fields * diff --git a/tests/Symfony/Tests/Component/Form/FieldGroupTest.php b/tests/Symfony/Tests/Component/Form/FieldGroupTest.php index 32f94aff06..71357afe36 100644 --- a/tests/Symfony/Tests/Component/Form/FieldGroupTest.php +++ b/tests/Symfony/Tests/Component/Form/FieldGroupTest.php @@ -130,15 +130,27 @@ class FieldGroupTest extends \PHPUnit_Framework_TestCase $this->assertFalse($group->hasErrors()); } - public function testBindForwardsBoundValues() + public function testBindForwardsPreprocessedData() { $field = $this->createMockField('firstName'); + + $group = $this->getMock( + 'Symfony\Tests\Component\Form\Fixtures\TestFieldGroup', + array('preprocessData'), // only mock preprocessData() + array('author') + ); + + // The data array is prepared directly after binding + $group->expects($this->once()) + ->method('preprocessData') + ->with($this->equalTo(array('firstName' => 'Bernhard'))) + ->will($this->returnValue(array('firstName' => 'preprocessed[Bernhard]'))); + $group->add($field); + + // The preprocessed data is then forwarded to the fields $field->expects($this->once()) ->method('bind') - ->with($this->equalTo('Bernhard')); - - $group = new TestFieldGroup('author'); - $group->add($field); + ->with($this->equalTo('preprocessed[Bernhard]')); $group->bind(array('firstName' => 'Bernhard')); }