class FileWidgetAjaxController

Same name in other branches
  1. 8.9.x core/modules/file/src/Controller/FileWidgetAjaxController.php \Drupal\file\Controller\FileWidgetAjaxController
  2. 10 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 10

Namespace

Drupal\file\Controller
View source
class FileWidgetAjaxController {
    
    /**
     * 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' => t('Starting upload...'),
            'percentage' => -1,
        ];
        $implementation = file_progress_implementation();
        if ($implementation == 'uploadprogress') {
            $status = uploadprogress_get_info($key);
            if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
                $progress['message'] = t('Uploading... (@current of @total)', [
                    '@current' => format_size($status['bytes_uploaded']),
                    '@total' => format_size($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.

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