From cd23b497d9267a6a14365ae60b39e82702ac1930 Mon Sep 17 00:00:00 2001 From: Robert Gruendler Date: Fri, 13 Apr 2012 13:33:19 +0200 Subject: [PATCH 1/2] fixed choice_list closure --- Form/Type/ModelType.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Form/Type/ModelType.php b/Form/Type/ModelType.php index 6b4db061a5..fd1b614d5a 100644 --- a/Form/Type/ModelType.php +++ b/Form/Type/ModelType.php @@ -12,6 +12,7 @@ namespace Sonata\AdminBundle\Form\Type; +use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\AbstractType; @@ -52,15 +53,19 @@ public function getDefaultOptions() 'parent' => 'choice', 'preferred_choices' => array(), 'choice_list' => function (Options $options, $previousValue) { - if (null === $previousValue) { - return new ModelChoiceList( - $options['model_manager'], - $options['class'], - $options['property'], - $options['query'], - $options['choices'] - ); + + if ($previousValue instanceof ChoiceListInterface + && count($choices = $previousValue->getChoices())) { + return $choices; } + + return new ModelChoiceList( + $options['model_manager'], + $options['class'], + $options['property'], + $options['query'], + $options['choices'] + ); } ); From 5371787c00ecc874b8601a0f47494faaec8e210e Mon Sep 17 00:00:00 2001 From: Robert Gruendler Date: Fri, 13 Apr 2012 16:15:55 +0200 Subject: [PATCH 2/2] fixed CS --- Form/Type/ModelType.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Form/Type/ModelType.php b/Form/Type/ModelType.php index fd1b614d5a..86b17ba62f 100644 --- a/Form/Type/ModelType.php +++ b/Form/Type/ModelType.php @@ -53,12 +53,11 @@ public function getDefaultOptions() 'parent' => 'choice', 'preferred_choices' => array(), 'choice_list' => function (Options $options, $previousValue) { - - if ($previousValue instanceof ChoiceListInterface + if ($previousValue instanceof ChoiceListInterface && count($choices = $previousValue->getChoices())) { return $choices; } - + return new ModelChoiceList( $options['model_manager'], $options['class'],