You are here

protected function TemporaryJsonapiFileFieldUploader::prepareFilename in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::prepareFilename()
  2. 9 core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::prepareFilename()

Prepares the filename to strip out any malicious extensions.

Parameters

string $filename: The file name.

array $validators: The array of upload validators.

Return value

string The prepared/munged filename.

File

core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php, line 439

Class

TemporaryJsonapiFileFieldUploader
Reads data from an upload stream and creates a corresponding file entity.

Namespace

Drupal\jsonapi\Controller

Code

protected function prepareFilename($filename, array &$validators) {

  // The actual extension validation occurs in
  // \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::validate().
  $extensions = $validators['file_validate_extensions'][0] ?? '';
  $event = new FileUploadSanitizeNameEvent($filename, $extensions);
  $this->eventDispatcher
    ->dispatch($event);
  return $event
    ->getFilename();
}