Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a72a5fa

Browse files
committed
[Form] Add support for \Traversable in 'choices' param of ChoiceType
1 parent 25ff59b commit a72a5fa

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
239239
));
240240

241241
$resolver->setAllowedTypes(array(
242-
'choices' => array('null', 'array'),
242+
'choices' => array('null', 'array', 'Traversable'),
243243
'choice_list' => array('null', 'Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface'),
244244
'preferred_choices' => 'array',
245245
));

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,13 @@ public function testInitializeWithDefaultObjectChoice()
16721672
$form->getViewData();
16731673
}
16741674

1675+
public function testChoicesOptionSupportsTraversable()
1676+
{
1677+
$this->factory->create('choice', null, array(
1678+
'choices' => new \ArrayObject($this->choices),
1679+
));
1680+
}
1681+
16751682
/**
16761683
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
16771684
*/

0 commit comments

Comments
 (0)