protected function FileUploadHandler::handleExtensionValidation in Drupal 10
Gets the list of allowed extensions and updates the validators.
This will add an extension validator to the list of validators if one is not set.
If the extension validator is set, but no extensions are specified, it means all extensions are allowed, so the validator is removed from the list of validators.
Parameters
array $validators: The file validators in use.
Return value
string The space delimited list of allowed file extensions.
1 call to FileUploadHandler::handleExtensionValidation()
- FileUploadHandler::handleFileUpload in core/
modules/ file/ src/ Upload/ FileUploadHandler.php - Creates a file from an upload.
File
- core/
modules/ file/ src/ Upload/ FileUploadHandler.php, line 309
Class
- FileUploadHandler
- Handles validating and creating file entities from file uploads.
Namespace
Drupal\file\UploadCode
protected function handleExtensionValidation(array &$validators) : string {
// Build a list of allowed extensions.
if (isset($validators['file_validate_extensions'])) {
if (!isset($validators['file_validate_extensions'][0])) {
// If 'file_validate_extensions' is set and the list is empty then the
// caller wants to allow any extension. In this case we have to remove the
// validator or else it will reject all extensions.
unset($validators['file_validate_extensions']);
}
}
else {
// No validator was provided, so add one using the default list.
// Build a default non-munged safe list for
// \Drupal\system\EventSubscriber\SecurityFileUploadEventSubscriber::sanitizeName().
$validators['file_validate_extensions'] = [
self::DEFAULT_EXTENSIONS,
];
}
return $validators['file_validate_extensions'][0] ?? '';
}