Skip to content

Commit 84c3473

Browse files
committed
bug #15069 [Form] Fixed: Data mappers always receive forms indexed by 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
2 parents 7e2cb33 + 6ba90c0 commit 84c3473

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ public function add($child, $type = null, array $options = array())
895895
$child->setParent($this);
896896

897897
if (!$this->lockSetData && $this->defaultDataSet && !$this->config->getInheritData()) {
898-
$iterator = new InheritDataAwareIterator(new \ArrayIterator(array($child)));
898+
$iterator = new InheritDataAwareIterator(new \ArrayIterator(array($child->getName() => $child)));
899899
$iterator = new \RecursiveIteratorIterator($iterator);
900900
$this->config->getDataMapper()->mapDataToForms($viewData, $iterator);
901901
}

Tests/CompoundFormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public function testAddMapsViewDataToFormIfInitialized()
352352
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator'))
353353
->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child, $test) {
354354
$test->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
355-
$test->assertSame(array($child), iterator_to_array($iterator));
355+
$test->assertSame(array($child->getName() => $child), iterator_to_array($iterator));
356356
}));
357357

358358
$form->initialize();

0 commit comments

Comments
 (0)