title: "Multiple Upload" with VichUploaderBundle on Symfony 3
body: <p>I try to allowed the multiple upload with the bundle VichUploader. On the project, i have a class Theater which own a main image but also a number of secondary images (Collection of images). Actually each secondary images is a Ressource.
  So a Theater have onetomany Resources and a Resource is connected to one theater.</p>
  
  <p>But when i try to create i can access to my form but i have an error when i try to save which is : </p>
  
  <pre><code>Expected argument of type "AppBundle\Entity\Resources", "AppBundle\Entity\Theatre" given 
  </code></pre>
  
  <p>Here this is my class Theater with only details for multiple upload :</p>
  
  <pre><code>namespace AppBundle\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\HttpFoundation\File\File;
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Component\Validator\Context\ExecutionContextInterface;
  use Vich\UploaderBundle\Mapping\Annotation as Vich;
  
  /**
  * Theatre
  *
  * @ORM\Table(name="theatre")
  * @ORM\Entity
  * @Vich\Uploadable
  */
  class Theatre
  {
  
  /**
   *  @var ArrayCollection
   * @ORM\OneToMany(targetEntity="Resources", mappedBy="theatre", cascade={"persist", "remove"}, orphanRemoval=true)
   */
  private $images;
  
  // ..
  
  /**
   * Constructor
   */
  public function __construct()
  {
      $this-&gt;images = new \Doctrine\Common\Collections\ArrayCollection();
  }
  
  // MultiUpload
  /**
   * @return ArrayCollection
   */
  public function getImages()
  {
      return $this-&gt;images;
  }
  
  /**
   * @param ArrayCollection $pictures
   */
  public function setImages($pictures)
  {
      $this-&gt;images = $pictures;
  }
  
  public function getAttachImages()
  {
      return null;
  }
  
  /**
   * @param array $files
   *
   * @return array
   */
  public function setAttachImages(array $files=array())
  {
      if (!$files) return [];
      foreach ($files as $file) {
          if (!$file) return [];
          $this-&gt;attachImages($file);
      }
      return [];
  }
  
  /**
   * @param UploadedFile|null $file
   */
  public function attachImages(UploadedFile $file=null)
  {
      if (!$file) {
          return;
      }
      $picture = new Resources();
      $picture-&gt;setImage($file);
      $this-&gt;addImage($picture);
  }
  
  
  
  /**
   * Add image.
   *
   * @param \AppBundle\Entity\Resources $image
   *
   *
   */
  public function addImage(\AppBundle\Entity\Resources $image)
  {
      $image-&gt;setTheatre($this);
      //$this-&gt;images-&gt;add($image);
      $this-&gt;images[] = $image;
  
      //return $this;
  }
  
  /**
   * Remove image.
   *
   * @param \AppBundle\Entity\Resources $image
   *
   *
   */
  public function removeImage(\AppBundle\Entity\Resources $image)
  {
      $image-&gt;setTheatre(null);
      $this-&gt;images-&gt;removeElement($image);
     // return $this-&gt;images-&gt;removeElement($image);
  }
  </code></pre>
  
  <p>Then my class Resources :</p>
  
  <pre><code>namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\HttpFoundation\File\File;
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Component\Validator\Context\ExecutionContextInterface;
  use Vich\UploaderBundle\Mapping\Annotation as Vich;
  
  /**
  * Resources
  *
  * @ORM\Table(name="resources")
  * @ORM\Entity
  * @Vich\Uploadable
  */
  class Resources
  {
  
   /**
   * @var Theatre
   * @ORM\ManyToOne(targetEntity="Theatre", inversedBy="images")
   */
  private $theatre;
  
  /**
   * @Vich\UploadableField(mapping="uploads_image", fileNameProperty="url")
   * @Assert\File(
   *      mimeTypes = {"image/png", "image/jpeg", "image/jpg"},
   *      mimeTypesMessage = "Please upload a valid valid IMAGE"
   * )
   *
   *
   * @var File $image
   */
  protected $image;
  
  /**
   * @ORM\Column(type="string", length=255, name="url")
   *
   * @var array $url
   */
  protected $url;
  
  
  /**
   *
   * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
   *
   * @return Theatre
   */
  public function setImage(File $image = null)
  {
      $this-&gt;image = $image;
  }
  
  public function getImage()
  {
      return $this-&gt;image;
  }
  
  // ..
  
    /**
   * Set theatre.
   *
   * @param \AppBundle\Entity\Theatre $theatre
   *
   * @return Resources
   */
  public function setTheatre(\AppBundle\Entity\Theatre $theatre)
  {
      $this-&gt;theatre = $theatre;
  
      return $this;
  }
  
  /**
   * Get theatre.
   *
   * @return \AppBundle\Entity\Theatre
   */
  public function getTheatre()
  {
      return $this-&gt;theatre;
  }
  
  /**
   * Set url.
   *
   * @param string $url
   *
   * @return Resources
   */
  public function setUrl($url)
  {
      $this-&gt;url = $url;
  
      return $this;
  }
  
  /**
   * Get url.
   *
   * @return array
   */
  public function getUrl()
  {
      return $this-&gt;url;
  }
  </code></pre>
  
  <p>Then I add to the builder : </p>
  
  <pre><code>namespace AppBundle\Form\Collection;
  
  use AppBundle\Entity\Theatre;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\FileType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  use Vich\UploaderBundle\Form\Type\VichFileType;
  
  
  class TheatreImages extends AbstractType{
  /**
   * @param FormBuilderInterface $builder
   * @param array                $options
   */
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('attachImages', FileType::class, ['multiple'=&gt;true, 'required'=&gt;false])
      ;
  
  
  }
  
  /**
   * @param OptionsResolver $resolver
   */
  public function configureOptions(OptionsResolver $resolver)
  {
      $resolver-&gt;setDefaults(array(
          'data_class' =&gt; Theatre::class,
      ));
  }
  
  /**
   * @return string
   */
  public function getName()
  {
      return 'app_theatreImages';
  }
  }
  </code></pre>
  
  <p>I add my config with the bundle easyAdminBundle:</p>
  
  <pre><code>easy_admin:
     entities:
      Theatre:
          class: AppBundle\Entity\Theatre
          list:
              title: 'Liste des théâtres'
              fields:
                  - 'Name'
                  - 'adress'
                  - 'Metro station'
                  - { property: 'Main image', type: 'image',  template: 'theatreFile.html.twig',  base_path: '%app.path.theatre_images%' }
  
          new:
              title: 'Création théâtre'
              fields:
                  - { type: 'section', label: 'Information du théâtre' }
                  - {property: 'name', label: 'Nom'}
                  - {property: 'number_of_seats', type: 'integer', label: 'Nombre de sièges'}
                  - {property: 'about', label: 'description'}
                  - { property: 'imageFile', type: 'vich_file', label: 'image', type_options: { required: false}}
                  - {property: 'images', type: 'collection', type_options: {entry_type: 'AppBundle\Form\Collection\TheatreImages', by_reference: false}}
                  - { type: 'section', label: 'Localisation du théâtre' }
                  - {property: 'adress', label: 'adresse'}
                  - {property: 'metro_station', label: 'Station de métro'}
                  - {property: 'location_coordinates', label: 'Coordonnées'}
          edit:
              title: "Édition théâtre"
              fields:
                  - { type: 'section', label: 'Information du théâtre' }
                  - {property: 'name', label: 'Nom'}
                  - {property: 'number_of_seats', type: 'integer', label: 'Nombre de sièges'}
                  - {property: 'about', label: 'description'}
                  - { property: 'imageFile', type: 'vich_file', label: 'image', type_options: { required: false}}
                  - {property: 'images', type: 'collection', type_options: {entry_type: 'AppBundle\Form\Collection\TheatreImages', by_reference: false}}
                  - { type: 'section', label: 'Localisation du théâtre' }
                  - {property: 'adress', label: 'adresse'}
                  - {property: 'metro_station', label: 'Station de métro'}
                  - {property: 'location_coordinates', label: 'Coordonnées'}
  </code></pre>
  
  <p>Thanks in advance.</p>