Skip to content

Commit a233824

Browse files
authored
Merge pull request #90 from systopia/fix-file-not-submitted
Ensure form is submitted as multipart/form-data in case a file field might be added dynamically
2 parents a1595a0 + a434898 commit a233824

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Form/Control/ArrayArrayFactory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ final class ArrayArrayFactory extends AbstractConcreteFormArrayFactory {
3939

4040
/**
4141
* {@inheritDoc}
42+
*
43+
* phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
4244
*/
4345
public function createFormArray(
46+
// phpcs:enable
4447
DefinitionInterface $definition,
4548
FormStateInterface $formState,
4649
FormArrayFactoryInterface $formArrayFactory
@@ -85,6 +88,16 @@ public function createFormArray(
8588
);
8689

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

0 commit comments

Comments
 (0)