function file_validate_name_length in Drupal 10
Same name and namespace in other branches
- 8 core/modules/file/file.module \file_validate_name_length()
- 6 includes/file.inc \file_validate_name_length()
- 7 includes/file.inc \file_validate_name_length()
- 9 core/modules/file/file.module \file_validate_name_length()
Checks for files with names longer than can be stored in the database.
Parameters
\Drupal\file\FileInterface $file: A file entity.
Return value
array An empty array if the file name length is smaller than the limit or an array containing an error message if it's not or is empty.
1 call to file_validate_name_length()
- ValidatorTest::testFileValidateNameLength in core/
modules/ file/ tests/ src/ Kernel/ ValidatorTest.php - This will ensure the filename length is valid.
3 string references to 'file_validate_name_length'
- FileUploadHandler::handleFileUpload in core/
modules/ file/ src/ Upload/ FileUploadHandler.php - Creates a file from an upload.
- FileUploadResource::getUploadValidators in core/
modules/ file/ src/ Plugin/ rest/ resource/ FileUploadResource.php - Retrieves the upload validators for a field definition.
- TemporaryJsonapiFileFieldUploader::getUploadValidators in core/
modules/ jsonapi/ src/ Controller/ TemporaryJsonapiFileFieldUploader.php - Retrieves the upload validators for a field definition.
File
- core/
modules/ file/ file.module, line 133 - Defines a "managed_file" Form API field and a "file" field for Field module.
Code
function file_validate_name_length(FileInterface $file) {
$errors = [];
if (!$file
->getFilename()) {
$errors[] = t("The file's name is empty. Please give a name to the file.");
}
if (strlen($file
->getFilename()) > 240) {
$errors[] = t("The file's name exceeds the 240 characters limit. Please rename the file and try again.");
}
return $errors;
}