file_validate_name_length

function file_validate_name_length

file_validate_name_length(FileInterface $file)

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.

File

core/modules/file/file.module, line 310
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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!file!file.module/function/file_validate_name_length/8.1.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部