VichUploaderBundle icon indicating copy to clipboard operation
VichUploaderBundle copied to clipboard

No thumbnails displayed by VichImageType inside of CollectionType Symfony 3.2

Open mattxtlm opened this issue 6 years ago • 4 comments

Hi there,

to be able to select multiple images (many-to-one relation), I used VichImageType inside a CollectionType in a Symfony 3.2 Form:

Parent Form:

public function buildForm(FormBuilderInterface $builder, array $options)
    {     
// ... some code 
       ->add($builder->create('images',CollectionType::class, [
                'entry_type' => ItemImageType::class,
                'entry_options' => [
                    'image_uri' => true
                ]
// ..

in ItemImageType I go:

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

When the form is rendered, everything works great (uploading, persisting to DB etc.), but the form won't display any thumbnails of existing images. If I use "ItemImageType" as standalone form, it does show me the thumbnail. So, I guess its properly configured.

The issue must be between the CollectionType and VichImageType processing this.

After some digging in the code, I found that inside class VichImageType the variable $object becomes null, when processing the CollectionType Form:

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $object = $form->getParent()->getData();
//...

That seems like the cause of the problem.

So here comes the one million dollar question: How do I fix this and have my thumbnails displayed?

Thx, Matt

mattxtlm avatar Aug 09 '17 07:08 mattxtlm

VichUploaderBundle version?

garak avatar Aug 11 '17 09:08 garak

From composer.json:

"vich/uploader-bundle": "^1.6",

mattxtlm avatar Aug 11 '17 10:08 mattxtlm

Hey, are there any new insights about this issue? Thanks.

mattxtlm avatar Nov 18 '17 06:11 mattxtlm

Are the object in your collection empty? Can you provide a basic Symfony project where it's possible to reproduce your issue?

garak avatar Nov 18 '17 15:11 garak