class FileWidgetAjaxController

Same name in other branches
  1. 9 core/modules/file/src/Controller/FileWidgetAjaxController.php \Drupal\file\Controller\FileWidgetAjaxController
  2. 8.9.x core/modules/file/src/Controller/FileWidgetAjaxController.php \Drupal\file\Controller\FileWidgetAjaxController
  3. 11.x core/modules/file/src/Controller/FileWidgetAjaxController.php \Drupal\file\Controller\FileWidgetAjaxController

Defines a controller to respond to file widget AJAX requests.

Hierarchy

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'] = 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 Overrides
FileWidgetAjaxController::progress public function Returns the progress status for a file upload process.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
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. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.