Sonataadminbundle: Unable to transform value for property path "tags": Expected an array. In ChoiceType

Created on 20 Jan 2016  路  1Comment  路  Source: sonata-project/SonataAdminBundle

Hi, I have problem with choice using multiple choice, if I use 'multiple'=>false it works but it's useless for collection.

  • Symfony 3.0.1
  • DoctrineODM

Document:

    /**
     * @var ArrayCollection<Tag> $tag
     * @ODM\ReferenceMany(targetDocument="Tag")
     */
    protected $tags;
    public function __construct()
    {
        $this->tags = new ArrayCollection();
    }

Admin (FormFields):

$tagQuery = $this->getModelManager()->createQuery('FitpointBundle:Tag')->execute();

...
            ->add(
                'tags',
                'choice',
                [
                    'multiple' => true,
                    'required' => false,
                    'choices' => $tagQuery,
                    'choice_label' => function ($tag, $key, $index) {
                        /** @var Tag $tag */
                        return $tag->getTitle();
                    },
                ]
            )
...

I try to use sonata_type_model but that ends with Notice: Undefined index: choice_list which is related to https://github.com/sonata-project/SonataAdminBundle/issues/3529

I also tried autocomplete with:

->add('tags', 'sonata_type_model_autocomplete', [
                'multiple' => true,
                'property'=>'title',
                'required' => false
            ])

error:

Catchable Fatal Error: Argument 1 passed to Sonata\AdminBundle\Form\DataTransformer\ModelToIdPropertyTransformer::__construct() must implement interface Sonata\AdminBundle\Model\ModelManagerInterface, null given, called in /<path>/vendor/sonata-project/admin-bundle/Form/Type/ModelAutocompleteType.php on line 37 and defined

Most helpful comment

This is solved in current 3.x branch

>All comments

This is solved in current 3.x branch

Was this page helpful?
0 / 5 - 0 ratings