فهرست منبع

Add ModelChoiceLoader for Sf3 compatibility.

Add condition on ModelChoiceLoader to avoid raising exception with
MultiChoice Selects in Sonata Admin Forms.
Badr HAKKARI 9 سال پیش
والد
کامیت
1b0784f646
1فایلهای تغییر یافته به همراه10 افزوده شده و 5 حذف شده
  1. 10 5
      Form/DataTransformer/ModelsToArrayTransformer.php

+ 10 - 5
Form/DataTransformer/ModelsToArrayTransformer.php

@@ -12,6 +12,7 @@
 namespace Sonata\AdminBundle\Form\DataTransformer;
 
 use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceList;
+use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceLoader;
 use Sonata\AdminBundle\Model\ModelManagerInterface;
 use Symfony\Component\Form\ChoiceList\LazyChoiceList;
 use Symfony\Component\Form\DataTransformerInterface;
@@ -44,14 +45,18 @@ class ModelsToArrayTransformer implements DataTransformerInterface
     /**
      * ModelsToArrayTransformer constructor.
      *
-     * @param ModelChoiceList|LazyChoiceList $choiceList
-     * @param ModelManagerInterface          $modelManager
-     * @param                                $class
+     * @param ModelChoiceList|LazyChoiceList|ModelChoiceLoader $choiceList
+     * @param ModelManagerInterface $modelManager
+     * @param $class
+     * @throws RuntimeException
      */
     public function __construct($choiceList, ModelManagerInterface $modelManager, $class)
     {
-        if (!$choiceList instanceof ModelChoiceList && !$choiceList instanceof LazyChoiceList) {
-            throw new RuntimeException('First param passed to ModelsToArrayTransformer should be instance of ModelChoiceList or LazyChoiceList');
+        if (!$choiceList instanceof ModelChoiceList
+            && !$choiceList instanceof ModelChoiceLoader
+            && !$choiceList instanceof LazyChoiceList) {
+            throw new RuntimeException('First param passed to ModelsToArrayTransformer should be instance of
+                ModelChoiceLoader or ModelChoiceList or LazyChoiceList');
         }
 
         $this->choiceList   = $choiceList;