Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FileUploadHandler.php

function FileUploadHandler::handleExtensionValidation

Gets the list of allowed extensions and updates the validators.

This will add an extension validator to the list of validators if one is not set.

If the extension validator is set, but no extensions are specified, it means all extensions are allowed, so the validator is removed from the list of validators.

Parameters

array $validators: The file validators in use.

Return value

string The space delimited list of allowed file extensions.

1 call to FileUploadHandler::handleExtensionValidation()
FileUploadHandler::handleFileUpload in core/modules/file/src/Upload/FileUploadHandler.php
Creates a file from an upload.

File

core/modules/file/src/Upload/FileUploadHandler.php, line 320

Class

FileUploadHandler
Handles validating and creating file entities from file uploads.

Namespace

Drupal\file\Upload

Code

protected function handleExtensionValidation(array &$validators) : string {
    // No validator was provided, so add one using the default list.
    // Build a default non-munged safe list for
    // \Drupal\system\EventSubscriber\SecurityFileUploadEventSubscriber::sanitizeName().
    if (!isset($validators['FileExtension'])) {
        $validators['FileExtension'] = [
            'extensions' => self::DEFAULT_EXTENSIONS,
        ];
        return self::DEFAULT_EXTENSIONS;
    }
    // Check if we want to allow all extensions.
    if (!isset($validators['FileExtension']['extensions'])) {
        // If 'FileExtension' is set and the list is empty then the caller wants
        // to allow any extension. In this case we have to remove the validator
        // or else it will reject all extensions.
        unset($validators['FileExtension']);
        return '';
    }
    return $validators['FileExtension']['extensions'];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal