bug #15662 [Form][2.7][ Choice type] fixed groups with empty array. (aitboudad)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form][2.7][ Choice type] fixed groups with empty array.

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

- [x] test

Commits
-------

835aa78 [Form][2.7][ Choice type] fixed groups with empty array.
This commit is contained in:
Fabien Potencier 2015-09-01 09:47:15 +02:00
commit db8420e6d5
2 changed files with 5 additions and 0 deletions

View File

@ -172,6 +172,10 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
private static function addChoiceViewsGroupedBy($groupBy, $label, $choices, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews)
{
foreach ($groupBy as $key => $value) {
if (null === $value) {
continue;
}
// Add the contents of groups to new ChoiceGroupView instances
if (is_array($value)) {
$preferredViewsForGroup = array();

View File

@ -536,6 +536,7 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase
$list = new ArrayChoiceList(array(
'Group 1' => array('A' => $this->obj1, 'B' => $this->obj2),
'Group 2' => array('C' => $this->obj3, 'D' => $this->obj4),
'Group empty' => array(),
));
$view = $this->factory->createView(