浏览代码

fixed choice_list closure

Robert Gruendler 13 年之前
父节点
当前提交
cd23b497d9
共有 1 个文件被更改,包括 13 次插入8 次删除
  1. 13 8
      Form/Type/ModelType.php

+ 13 - 8
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 @@ class ModelType extends AbstractType
             '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']
+                );
             }
         );