I have one Entity Hike with oneTomMany mapped field
/**
* @ORM\OneToMany(targetEntity=HikePhotos::class, mappedBy="hikeId", orphanRemoval=true)
*/
private $hikePhotos;
public function __construct()
{
$this->hikePhotos = new ArrayCollection();
}
And HikePhotos entity
/**
* @ORM\ManyToOne(targetEntity=Hike::class, inversedBy="hikePhotos")
* @ORM\JoinColumn(nullable=false)
*/
private $hikeId;
/**
* @ORM\Column(type="text")
*/
private $filePath;
I render HikePhotos in Hike form using the CollectionType
$builder
->add('hikePhotos', CollectionType::class, [
'entry_type' => HikePhotosType::class,
'allow_delete' => true,
'allow_add' => true,
'by_reference' => false
]);
Generated form contains N html input type file what I want is to list existing photos without input, and only one to add photos.
Actual output
<input type="file" id="hike_hikePhotos_0_filePath" name="hike[hikePhotos][0][filePath]" required="required" class="custom-file-input" lang="fr">
<input type="file" id="hike_hikePhotos_0_filePath" name="hike[hikePhotos][1][filePath]" required="required" class="custom-file-input" lang="fr">
Expected something like
<!-- existing photos -->
<span name="hike[hikePhotos][0][filePath]">photo1.jpg</span> <a href="">remove</a>
<span name="hike[hikePhotos][1][filePath]">photo2.jpg</span> <a href="">remove</a>
Add photo
<input type='file'/>