Skip to content

Commit

Permalink
feat: add MimeType validator to FileUpload form element
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdmlln committed Nov 13, 2024
1 parent 8993c31 commit f5db9b3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Classes/Form/FormDefinitionDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
],
];
}
}
}
}

0 comments on commit f5db9b3

Please sign in to comment.