You are here

function file_validate_name_length in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 array. If the file name is too long, it will contain an error message.

1 call to file_validate_name_length()
ValidatorTest::testFileValidateNameLength in core/modules/file/src/Tests/ValidatorTest.php
This will ensure the filename length is valid.

File

core/modules/file/file.module, line 306
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_validate_name_length(FileInterface $file) {
  $errors = array();
  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;
}