diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 7b92200..ac9086a 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -720,101 +720,6 @@ function file_cron() { } /** - * Ajax callback: Processes file uploads and deletions. - * - * This rebuilds the form element for a particular field item. As long as the - * form processing is properly encapsulated in the widget element the form - * should rebuild correctly using FAPI without the need for additional callbacks - * or processing. - * - * @see file_menu() - */ -function file_ajax_upload() { - $form_parents = func_get_args(); - $form_build_id = (string) array_pop($form_parents); - - $request = \Drupal::request(); - if (!$request->request->has('form_build_id') || $form_build_id != $request->request->get('form_build_id')) { - // Invalid request. - drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error'); - $response = new AjaxResponse(); - return $response->addCommand(new ReplaceCommand(NULL, theme('status_messages'))); - } - - list($form, $form_state) = ajax_get_form(); - - if (!$form) { - // Invalid form_build_id. - drupal_set_message(t('An unrecoverable error occurred. Use of this form has expired. Try reloading the page and submitting again.'), 'error'); - $response = new AjaxResponse(); - return $response->addCommand(new ReplaceCommand(NULL, theme('status_messages'))); - } - - // Get the current element and count the number of files. - $current_element = $form; - foreach ($form_parents as $parent) { - $current_element = $current_element[$parent]; - } - $current_file_count = isset($current_element['#file_upload_delta']) ? $current_element['#file_upload_delta'] : 0; - - // Process user input. $form and $form_state are modified in the process. - drupal_process_form($form['#form_id'], $form, $form_state); - - // Retrieve the element to be rendered. - foreach ($form_parents as $parent) { - $form = $form[$parent]; - } - - // Add the special Ajax class if a new file was added. - if (isset($form['#file_upload_delta']) && $current_file_count < $form['#file_upload_delta']) { - $form[$current_file_count]['#attributes']['class'][] = 'ajax-new-content'; - } - // Otherwise just add the new content class on a placeholder. - else { - $form['#suffix'] .= ''; - } - - $form['#prefix'] .= theme('status_messages'); - $output = drupal_render($form); - $js = drupal_add_js(); - $settings = drupal_merge_js_settings($js['settings']['data']); - - $response = new AjaxResponse(); - return $response->addCommand(new ReplaceCommand(NULL, $output, $settings)); -} - -/** - * Ajax callback: Retrieves upload progress. - * - * @param $key - * The unique key for this upload process. - */ -function file_ajax_progress($key) { - $progress = array( - '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)', array('@current' => format_size($status['bytes_uploaded']), '@total' => format_size($status['bytes_total']))); - $progress['percentage'] = round(100 * $status['bytes_uploaded'] / $status['bytes_total']); - } - } - elseif ($implementation == 'apc') { - $status = apc_fetch('upload_' . $key); - if (isset($status['current']) && !empty($status['total'])) { - $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['current']), '@total' => format_size($status['total']))); - $progress['percentage'] = round(100 * $status['current'] / $status['total']); - } - } - - return new JsonResponse($progress); -} - -/** * Determines the preferred upload progress implementation. * * @return diff --git a/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php b/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php index efd42e5..da36c07 100644 --- a/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php +++ b/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php @@ -21,7 +21,7 @@ class FileWidgetAjaxController extends FormAjaxController { /** - * Handle form AJAX request. + * Processes AJAX file uploads. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request object. @@ -81,7 +81,7 @@ public function upload(Request $request) { } /** - * Handle AJAX upload progress request. + * Returns the progress status for a file upload process. * * @param string $key * The unique key for this upload process.