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

Breadcrumb

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

class FileWidgetAjaxController

Defines a controller to respond to file widget AJAX requests.

Hierarchy

  • class \Drupal\file\Controller\FileWidgetAjaxController uses \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of FileWidgetAjaxController

File

core/modules/file/src/Controller/FileWidgetAjaxController.php, line 12

Namespace

Drupal\file\Controller
View source
class FileWidgetAjaxController {
    use StringTranslationTrait;
    
    /**
     * Returns the progress status for a file upload process.
     *
     * @param string $key
     *   The unique key for this upload process.
     *
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     *   A JsonResponse object.
     */
    public function progress($key) {
        $progress = [
            'message' => $this->t('Starting upload...'),
            'percentage' => -1,
        ];
        if (extension_loaded('uploadprogress')) {
            $status = uploadprogress_get_info($key);
            if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
                $progress['message'] = $this->t('Uploading... (@current of @total)', [
                    '@current' => ByteSizeMarkup::create($status['bytes_uploaded']),
                    '@total' => ByteSizeMarkup::create($status['bytes_total']),
                ]);
                $progress['percentage'] = round(100 * $status['bytes_uploaded'] / $status['bytes_total']);
            }
        }
        return new JsonResponse($progress);
    }

}

Members

Title Sort descending Modifiers Object type Summary
FileWidgetAjaxController::progress public function Returns the progress status for a file upload process.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use.
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

API Navigation

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