[Form] Allow empty choices array for ChoiceType
This commit is contained in:
parent
92cb685ebc
commit
dbaddbb7a8
@ -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".');
|
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.');
|
throw new FormException('Either the option "choices" or "choice_list" must be set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -662,4 +662,12 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->assertSame('name[]', $view->get('full_name'));
|
$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(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user