Skip to content

Commit fc7155e

Browse files
author
Dominic Tubach
committed
Ensure form is submitted as multipart/form-data in case a file field might be added dynamically
1 parent a1595a0 commit fc7155e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Form/Control/ArrayArrayFactory.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ public function createFormArray(
8585
);
8686

8787
if (0 === $numItems) {
88+
if (0 !== $definition->getMaxItems()) {
89+
// There might be a file field in the child elements. To ensure that the
90+
// form is sent as multipart/form-data in case a file field is
91+
// dynamically added, we claim that the form has a file element.
92+
// If there's no file field initially, the form would be sent as
93+
// application/x-www-form-urlencoded, i.e. file contents wouldn't be
94+
// submitted.
95+
$formState->setHasFileElement(TRUE);
96+
}
97+
8898
// Ensure we get an empty array if there's no item.
8999
$form[] = [
90100
'#type' => 'hidden',

0 commit comments

Comments
 (0)