You are here

public function VideoUploadWidget::getUploadValidators in Video 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/VideoUploadWidget.php \Drupal\video\Plugin\Field\FieldWidget\VideoUploadWidget::getUploadValidators()

Retrieves the upload validators for a video 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 VideoUploadWidget::getUploadValidators()
VideoUploadWidget::formElement in src/Plugin/Field/FieldWidget/VideoUploadWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/VideoUploadWidget.php, line 249

Class

VideoUploadWidget
Plugin implementation of the 'video_upload' widget.

Namespace

Drupal\video\Plugin\Field\FieldWidget

Code

public function getUploadValidators() {
  $validators = [];
  $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'] = [
    $max_filesize,
  ];

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