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
This commit is contained in:
commit
38c08d1fb3
@ -895,7 +895,7 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
$child->setParent($this);
|
$child->setParent($this);
|
||||||
|
|
||||||
if (!$this->lockSetData && $this->defaultDataSet && !$this->config->getInheritData()) {
|
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);
|
$iterator = new \RecursiveIteratorIterator($iterator);
|
||||||
$this->config->getDataMapper()->mapDataToForms($viewData, $iterator);
|
$this->config->getDataMapper()->mapDataToForms($viewData, $iterator);
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ class CompoundFormTest extends AbstractFormTest
|
|||||||
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator'))
|
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator'))
|
||||||
->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child, $test) {
|
->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child, $test) {
|
||||||
$test->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
|
$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();
|
$form->initialize();
|
||||||
|
Reference in New Issue
Block a user