function file_field_widget_upload_validators

Retrieves the upload validators for a file field.

Parameters

$field: A field array.

Return value

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

1 call to file_field_widget_upload_validators()
FileWidget::formElement in drupal/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php
Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().

File

drupal/core/modules/file/file.field.inc, line 323
Field module functionality for the File module.

Code

function file_field_widget_upload_validators($field, $instance) {

  // Cap the upload size according to the PHP limit.
  $max_filesize = parse_size(file_upload_max_size());
  if (!empty($instance['settings']['max_filesize']) && parse_size($instance['settings']['max_filesize']) < $max_filesize) {
    $max_filesize = parse_size($instance['settings']['max_filesize']);
  }
  $validators = array();

  // 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($instance['settings']['file_extensions'])) {
    $validators['file_validate_extensions'] = array(
      $instance['settings']['file_extensions'],
    );
  }
  return $validators;
}