0
votes

I've a trouble with the bundle VichUploaderBundle with Symfony 4. I've follow a tutorial to make an upload with VichUploaderBundle to upload multiple files.

My problem is that the input form to upload the file is never render. But I don't see what it's wrong with my Type file.

In my MemberType who can find all fiels, I've

...
            ->add('member_files', CollectionType::class, [
                'label' => 'Add a file',
                'entry_type' => MemberFilesType::class,
                'allow_add' => true,
                'allow_delete' => true,
                'prototype' => true
            ])
...

And my MemberFilesType is :

<?php

namespace App\Form;

use App\Entity\MemberFiles;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Vich\UploaderBundle\Form\Type\VichImageType;


class MemberFilesType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('imageFile', VichImageType::class, [
                'required' => false,
                'download_uri' => true,
                'image_uri' => true
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => MemberFiles::class,
        ]);
    }
}

Do you have an idea ?

1
What do you mean by "is never render"? What happens instead? - Nico Haase
Thank you for your answer! The label is present, but not the field... - Galn89

1 Answers

0
votes

If you are working with a Member with no MemberFiles yet (empty collection) then that is what is expected. There are no collection entries because there are none persisted, try adding a new MemberFiles to the Member before you create the form.

In your controller action:

if(empty($member->getMemberFiles())){
  $member->addMemberFile(new MemberFiles());
}
$form = $this->createForm(MemberType::class, $member);