Skip to content

Commit 594aedd

Browse files
committed
Bugfix if own subtype of afe_single_upload
Fixes a bug when creating an own form type which has afe_single_upload as a parent. When creating a form type with afe_single_upload as parent the file on the entity is not set correctly. Instead it is set to array([file] => [UploadedFile]). This happens because the SingleUploadSubscriber only checks the actual form field onto it's type, but not the parents. So if you extend the afe_single_upload its behavior changes because of that. The fix just recurses over all parents and checks if the form extends from afe_single_upload.
1 parent 7fd778c commit 594aedd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Form/EventListener/SingleUploadSubscriber.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function preSubmit(FormEvent $event)
3131
$post = $event->getData();
3232

3333
foreach ($form->all() as $child) {
34-
if ($child->getConfig()->getType()->getName() === 'afe_single_upload') {
34+
if ($this->isFieldSingleUpload($child->getConfig()->getType())) {
3535
$childPost = $post[$child->getName()];
3636
$options = $child->getConfig()->getOptions();
3737

@@ -118,4 +118,12 @@ public function postSubmit(FormEvent $event)
118118
}
119119
}
120120
}
121+
122+
private function isFieldSingleUpload(ResolvedFormTypeInterface $formTypeInterface = null)
123+
{
124+
if($formTypeInterface == null) return false;
125+
if($formTypeInterface->getName() == 'afe_single_upload') return true;
126+
127+
return $this->isFieldSingleUpload($formTypeInterface->getParent());
128+
}
121129
}

0 commit comments

Comments
 (0)