Symfony 3 EasyAdmin and VichUploader for multiple file downloads with a given error type

I have a problem when I want to use these 3 things together. I give this error.

The expected argument of type "AppBundle \ Entity \ Images", "array" specified

I think my form gives an array, and I don't know how to solve this problem.

This is my config.yml

form:
                fields:
                    - 'name'
                    #- { property: 'image', type: 'vich_image' } #, type_options: { multiple: true, label: 'Image', data_class: null } }
                    - { property: 'images', type: 'collection' , type_options: { entry_type: 'AppBundle\Form\ProductImageType', by_reference: false } }
                    - { property: 'date', type: 'integer', format: '%d' }
                    - { property: 'description', type: 'ckeditor' }
                    - { property: 'long_description', type: 'ckeditor' }

And the form:

class ProductImageType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('image', VichImageType::class, array(
                'required'      => true,
                //'mapped'       => 'product',
                'allow_delete'  => true,
                'by_reference'  => false
            ))
        ;
    }
    public function setDefaultOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => '\AppBundle\Entity\Images',
        ));
    }
}

The essence of the product (this is only part of this):

namespace AppBundle\Entity;


use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 * @ORM\Table(name="product")
 */

class Product
{

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Images", mappedBy="product", cascade={"persist","remove"}, orphanRemoval=true)
     */
    protected $images;

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this->images = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add images
     *
     * @param \AppBundle\Entity\Images $image
     *
     * @return Product
     */
    public function addImage(Images $image){
        $this->images[] = $image;
        $image->setProduct($this);

        return $this;
    }
}

I don’t know what happened there. This array is as follows:

 Form ->submit (array('name' => 'gh', 'date' => '2012', 'description' => '<p>ghgh</p> ', 'long_description' => '<p>ghgh</p> ', '_token' => 'GCVXd4ASZpdoOakbu1cfMLkTBQN0-sy1kNql4inYPTw', 'images' => array(array('image' => array('file' => object(UploadedFile))))), true) 
+4
source share

All Articles