Description
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