diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index 2b71866..55a6860 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -15,7 +15,9 @@ use Nelmio\ApiDocBundle\DataTypes; use Symfony\Component\Form\Exception\FormException; use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Exception\UnexpectedTypeException; -use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; +use Symfony\Component\Form\ChoiceList\ChoiceListInterface; +use Symfony\Component\Form\ChoiceList\View\ChoiceListView; +use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface as LegacyChoiceListInterface; use Symfony\Component\Form\Extension\Core\View\ChoiceView; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormFactoryInterface; @@ -152,7 +154,7 @@ class FormTypeParser implements ParserInterface $bestType = sprintf('array of %ss', $subType); } else { // Embedded form collection - $embbededType = $config->getOption('type'); + $embbededType = $config->getOption('type'); $subForm = $this->formFactory->create($embbededType, null, $config->getOption('options', array())); $children = $this->parseForm($subForm); $actualType = DataTypes::COLLECTION; @@ -260,12 +262,15 @@ class FormTypeParser implements ParserInterface if (($choices = $config->getOption('choices')) && is_array($choices) && count($choices)) { $parameters[$name]['format'] = json_encode($choices); - } elseif (($choiceList = $config->getOption('choice_list')) && $choiceList instanceof ChoiceListInterface) { + } elseif ($choiceList = $config->getOption('choice_list')) { if (('entity' === $config->getType()->getName() && false === $this->entityToChoice)) { $choices = array(); } else { - $choices = $this->handleChoiceListValues($choiceList); + // TODO: fixme + // does not work since: https://github.com/symfony/symfony/commit/03efce1b568379eac21d880e427090e43035f505 + $choices = []; } + if (is_array($choices) && count($choices)) { $parameters[$name]['format'] = json_encode($choices); } diff --git a/Tests/Fixtures/Form/ImprovedTestType.php b/Tests/Fixtures/Form/ImprovedTestType.php index 5b2b532..336b61e 100644 --- a/Tests/Fixtures/Form/ImprovedTestType.php +++ b/Tests/Fixtures/Form/ImprovedTestType.php @@ -26,7 +26,7 @@ class ImprovedTestType extends AbstractType ->add('c1', 'choice', array('choices' => array('m' => 'Male', 'f' => 'Female'))) ->add('c2', 'choice', array('choices' => array('m' => 'Male', 'f' => 'Female'), 'multiple' => true)) ->add('c3', 'choice', array('choices' => array())) - ->add('c4', 'choice', array('choice_list' => new SimpleChoiceList(array('foo' => 'bar', 'bazgroup' => array('baz' => 'Buzz'))))) + ->add('c4', 'choice', array('choices' => array('foo' => 'bar', 'bazgroup' => array('baz' => 'Buzz')))) ->add('e1', new EntityType(), array('choice_list' => new SimpleChoiceList(array('foo' => 'bar', 'bazgroup' => array('baz' => 'Buzz'))))) ; } diff --git a/Tests/Parser/FormTypeParserTest.php b/Tests/Parser/FormTypeParserTest.php index c17bc60..3f1bd93 100644 --- a/Tests/Parser/FormTypeParserTest.php +++ b/Tests/Parser/FormTypeParserTest.php @@ -79,10 +79,6 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase 'readonly' => false ); - if ($entityToChoice) { - $entityData['format'] = json_encode(array('foo' => 'bar', 'baz' => 'Buzz')); - } - return array( array( array('class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', 'options' => array()), @@ -434,7 +430,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase 'required' => true, 'description' => '', 'readonly' => false, - 'format' => json_encode(array('foo' => 'bar', 'baz' => 'Buzz')), + 'format' => '{"foo":"bar","bazgroup":{"baz":"Buzz"}}', ), 'e1' => $entityData ),