diff --git a/Classes/Form/FormDefinitionDecorator.php b/Classes/Form/FormDefinitionDecorator.php index 26eadf6..8cd747b 100644 --- a/Classes/Form/FormDefinitionDecorator.php +++ b/Classes/Form/FormDefinitionDecorator.php @@ -41,6 +41,7 @@ protected function overrideDefinition(array $decorated, array $definition, int $ $this->setNotEmptyValidationErrorMessages($element); $this->setCheckboxLinks($element); $this->setFileSizeValidatorBytes($element); + $this->setMimeTypeValidator($element); } return $decorated; } @@ -104,4 +105,23 @@ private function setFileSizeValidatorBytes(array &$element): void } } } + + /** + * @param mixed[] $element + */ + private function setMimeTypeValidator(array &$element): void + { + if ($element['type'] === 'FileUpload') { + $mimeTypes = $element['properties']['allowedMimeTypes'] ?? []; + + if (!empty($mimeTypes)) { + $element['validators'][] = [ + 'identifier' => 'MimeType', + 'options' => [ + 'allowed' => $mimeTypes, + ], + ]; + } + } + } }