You are here

function webform_file_validate_name_length in Webform 6.x

Same name and namespace in other branches
  1. 8.5 webform.module \webform_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.

See also

file_validate_name_length()

File

./webform.module, line 805
Enables the creation of webforms and questionnaires.

Code

function webform_file_validate_name_length(FileInterface $file) {
  $errors = [];

  // Don't display error is the file_validate_name_length() has already
  // displayed a warning because the files length is over 240.
  if (strlen($file
    ->getFilename()) > 240) {
    return $errors;
  }
  if (strlen($file
    ->getFilename()) > 150) {
    $errors[] = t("The file's name exceeds the Webform module's 150 characters limit. Please rename the file and try again.");
  }
  return $errors;
}