[Form] Allow empty choices array for ChoiceType

This commit is contained in:
Thomas Chmielowiec 2012-02-07 21:53:27 +01:00
parent 92cb685ebc
commit dbaddbb7a8
2 changed files with 9 additions and 1 deletions

View File

@ -37,7 +37,7 @@ class ChoiceType extends AbstractType
throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface".');
}
if (!$options['choice_list'] && !$options['choices']) {
if (!$options['choice_list'] && !is_array($options['choices']) && !$options['choices'] instanceof \Traversable) {
throw new FormException('Either the option "choices" or "choice_list" must be set.');
}

View File

@ -662,4 +662,12 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertSame('name[]', $view->get('full_name'));
}
// https://github.com/symfony/symfony/issues/3298
public function testInitializeWithEmptyChoices()
{
$this->factory->createNamed('choice', 'name', null, array(
'choices' => array(),
));
}
}