diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index bc4e0876d8420..996f5cfcf9904 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -148,7 +148,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) // with the string value so it can be matched in // {@link \Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper::mapDataToForms()} $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { - $choiceList = $event->getForm()->getConfig()->getOption('choice_list'); + $choiceList = $event->getForm()->getConfig()->getAttribute('choice_list'); $value = current($choiceList->getValuesForChoices(array($event->getData()))); $event->setData((string) $value); }); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index ad289c6443152..a9cc7b1d42d5f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -30,14 +30,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase 'n/a' => '', ); - private $numericChoicesFlipped = array( - 0 => 'Bernhard', - 1 => 'Fabien', - 2 => 'Kris', - 3 => 'Jon', - 4 => 'Roman', - ); - private $objectChoices; protected $groupedChoices = array( @@ -110,9 +102,8 @@ public function testExpandedChoicesOptionsTurnIntoChildren() public function testChoiceListWithScalarValues() { - $view = $this->factory->create('choice', null, array( + $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'choices' => $this->scalarChoices, - 'choices_as_values' => true, ))->createView(); $this->assertSame('1', $view->vars['choices'][0]->value); @@ -125,9 +116,8 @@ public function testChoiceListWithScalarValues() public function testChoiceListWithScalarValuesAndFalseAsPreSetData() { - $view = $this->factory->create('choice', false, array( + $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'choices' => $this->scalarChoices, - 'choices_as_values' => true, ))->createView(); $this->assertTrue($view->vars['is_selected']($view->vars['choices'][1]->value, $view->vars['value']), 'False value should be pre selected'); @@ -135,9 +125,8 @@ public function testChoiceListWithScalarValuesAndFalseAsPreSetData() public function testExpandedChoiceListWithScalarValues() { - $view = $this->factory->create('choice', null, array( + $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'choices' => $this->scalarChoices, - 'choices_as_values' => true, 'expanded' => true, ))->createView(); @@ -148,9 +137,8 @@ public function testExpandedChoiceListWithScalarValues() public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData() { - $view = $this->factory->create('choice', false, array( + $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'choices' => $this->scalarChoices, - 'choices_as_values' => true, 'expanded' => true, ))->createView(); @@ -217,7 +205,7 @@ public function testPlaceholderNotPresentIfEmptyChoice() public function testPlaceholderWithBooleanChoices() { - $form = $this->factory->create('choice', null, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'multiple' => false, 'expanded' => false, 'required' => false, @@ -226,7 +214,6 @@ public function testPlaceholderWithBooleanChoices() 'No' => false, ), 'placeholder' => 'Select an option', - 'choices_as_values' => true, )); $view = $form->createView(); @@ -239,7 +226,7 @@ public function testPlaceholderWithBooleanChoices() public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() { - $form = $this->factory->create('choice', false, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'multiple' => false, 'expanded' => false, 'required' => false, @@ -248,7 +235,6 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() 'No' => false, ), 'placeholder' => 'Select an option', - 'choices_as_values' => true, )); $view = $form->createView(); @@ -261,7 +247,7 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() public function testPlaceholderWithExpandedBooleanChoices() { - $form = $this->factory->create('choice', null, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -270,7 +256,6 @@ public function testPlaceholderWithExpandedBooleanChoices() 'No' => false, ), 'placeholder' => 'Select an option', - 'choices_as_values' => true, )); $this->assertTrue(isset($form['placeholder']), 'Placeholder should be set'); @@ -286,7 +271,7 @@ public function testPlaceholderWithExpandedBooleanChoices() public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetData() { - $form = $this->factory->create('choice', false, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -295,7 +280,6 @@ public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetDat 'No' => false, ), 'placeholder' => 'Select an option', - 'choices_as_values' => true, )); $this->assertTrue(isset($form['placeholder']), 'Placeholder should be set');