diff --git a/Form/DataTransformer/ModelsToArrayTransformer.php b/Form/DataTransformer/ModelsToArrayTransformer.php index 06ad84aa00..9e5c7bf02d 100644 --- a/Form/DataTransformer/ModelsToArrayTransformer.php +++ b/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,19 @@ 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; diff --git a/Form/Type/ModelType.php b/Form/Type/ModelType.php index 500a89ae34..c6ab0bb6b2 100644 --- a/Form/Type/ModelType.php +++ b/Form/Type/ModelType.php @@ -51,7 +51,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['multiple']) { if (array_key_exists('choice_loader', $options) && $options['choice_loader'] !== null) { // SF2.7+ - $builder->addViewTransformer(new ModelsToArrayTransformer($options['choice_list'], $options['model_manager'], $options['class']), true); + $builder->addViewTransformer(new ModelsToArrayTransformer( + $options['choice_loader'], + $options['model_manager'], + $options['class']), true); } else { $builder->addViewTransformer(new LegacyModelsToArrayTransformer($options['choice_list']), true); }