I'm using VichUploaderBundle in Symfony 4 and I have a question about using a form to send in a bunch of photos. To do this I have to use CollectionType and a one-to-many relationship (One product has several photos). Below I present the code which only shows me an empty frame of the form, and it lacks buttons for adding photos as they are in this uploader. I do not understand why this is happening.
Product entity (one-to-many):
/**
* @var ProductMultiImage[]
* One Product has Many Images.
* @ORM\OneToMany(targetEntity="App\Entity\Image\ProductMultiImage", mappedBy="product", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $productMultiImages = null;
Image entity (many-to-one):
/**
* Many Images have One Product.
* @ORM\ManyToOne(targetEntity="App\Entity\Admin\Product", inversedBy="productMultiImages", cascade={"persist"})
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=true)
*/
private $product = null;
Form for adding photos:
class ProductImageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('productMultiImages', CollectionType::class, array(
'data_class' => ImageType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
))
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => null,
]);
}
}
ImageType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('imageFile', VichImageType::class)
;
}
Where i can find any solution ?