You are here

public function FileItem::getUploadValidators in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::getUploadValidators()

Retrieves the upload validators for a file field.

Return value

array An array suitable for passing to file_save_upload() or the file field element's '#upload_validators' property.

1 call to FileItem::getUploadValidators()
ImageItem::defaultImageForm in core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
Builds the default_image details element.

File

core/modules/file/src/Plugin/Field/FieldType/FileItem.php, line 301
Contains \Drupal\file\Plugin\Field\FieldType\FileItem.

Class

FileItem
Plugin implementation of the 'file' field type.

Namespace

Drupal\file\Plugin\Field\FieldType

Code

public function getUploadValidators() {
  $validators = array();
  $settings = $this
    ->getSettings();

  // Cap the upload size according to the PHP limit.
  $max_filesize = Bytes::toInt(file_upload_max_size());
  if (!empty($settings['max_filesize'])) {
    $max_filesize = min($max_filesize, Bytes::toInt($settings['max_filesize']));
  }

  // There is always a file size limit due to the PHP server limit.
  $validators['file_validate_size'] = array(
    $max_filesize,
  );

  // Add the extension check if necessary.
  if (!empty($settings['file_extensions'])) {
    $validators['file_validate_extensions'] = array(
      $settings['file_extensions'],
    );
  }
  return $validators;
}