Skip to content

Commit

Permalink
bug #15069 [Form] Fixed: Data mappers always receive forms indexed by…
Browse files Browse the repository at this point in the history
… their names (webmozart)

This PR was merged into the 2.3 branch.

Discussion
----------

[Form] Fixed: Data mappers always receive forms indexed by their names

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR facilitates writing domain-specific data mappers, since it guarantees that you can access forms by name in the data mapper methods. Currently, `Form::add()` does not set the index of the array passed to the data mapper to the form's name.

Commits
-------

86b7fe5 [Form] Fixed: Data mappers always receive forms indexed by their names
  • Loading branch information
fabpot committed Jun 30, 2015
2 parents f28ee56 + 86b7fe5 commit 38c08d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Form.php
Expand Up @@ -895,7 +895,7 @@ public function add($child, $type = null, array $options = array())
$child->setParent($this);

if (!$this->lockSetData && $this->defaultDataSet && !$this->config->getInheritData()) {
$iterator = new InheritDataAwareIterator(new \ArrayIterator(array($child)));
$iterator = new InheritDataAwareIterator(new \ArrayIterator(array($child->getName() => $child)));
$iterator = new \RecursiveIteratorIterator($iterator);
$this->config->getDataMapper()->mapDataToForms($viewData, $iterator);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Tests/CompoundFormTest.php
Expand Up @@ -352,7 +352,7 @@ public function testAddMapsViewDataToFormIfInitialized()
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator'))
->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child, $test) {
$test->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
$test->assertSame(array($child), iterator_to_array($iterator));
$test->assertSame(array($child->getName() => $child), iterator_to_array($iterator));
}));

$form->initialize();
Expand Down

0 comments on commit 38c08d1

Please sign in to comment.