Skip to content

Commit

Permalink
FilePondCollectionType now honors allow_delete
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Oct 19, 2023
1 parent 9f9d6d6 commit 9053fee
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/file-filepond/src/FilePondCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FilePondCollectionType extends FileType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
$incomingFiles = $event->getData();
if (!is_array($incomingFiles)) {
throw new \InvalidArgumentException('Incoming files must be an array');
Expand All @@ -46,9 +46,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void

$newData = $entityFiles->toArray();

foreach ($newData as $key => $file) {
if (!in_array((string) $key, $incomingFiles, true)) {
unset($newData[$key]);
if ($options['allow_delete'] === true) {
foreach ($newData as $key => $file) {
if (!in_array((string) $key, $incomingFiles, true)) {
unset($newData[$key]);
}
}
}

Expand Down

0 comments on commit 9053fee

Please sign in to comment.