diff --git a/core/lib/Drupal/Core/Ajax/AjaxCommandInterface.php b/core/lib/Drupal/Core/Ajax/AjaxCommandInterface.php new file mode 100644 index 0000000..7b4ebfe --- /dev/null +++ b/core/lib/Drupal/Core/Ajax/AjaxCommandInterface.php @@ -0,0 +1,11 @@ +selector = $selector; + $this->html = $html; + $this->settings = $settings; + } + + public function render() { + + return array( + 'command' => 'insert', + 'method' => 'replaceWith', + 'selector' => $this->selector, + 'data' => $this->html, + 'settings' => $this->settings, + ); + } + +} \ No newline at end of file diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponse.php b/core/lib/Drupal/Core/Ajax/AjaxResponse.php new file mode 100644 index 0000000..79f9b7b --- /dev/null +++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php @@ -0,0 +1,33 @@ +commands[] = $command->render(); + } + + /** + * Sets the response's data to be the array of AJAX commands. + */ + public function ajaxPrepare() { + parent::setData($this->commands); + } + +} \ No newline at end of file diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 4e6c8eb..f3d7e9d 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -797,9 +797,10 @@ function file_ajax_upload() { if (empty($_POST['form_build_id']) || $form_build_id != $_POST['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'); - $commands = array(); - $commands[] = ajax_command_replace(NULL, theme('status_messages')); - return array('#type' => 'ajax', '#commands' => $commands); + $response = new AjaxResponse(); + $response->addCommand(new AjaxCommandReplace(NULL, theme('status_messages'))); + $response->ajaxPrepare(); + return $response; } list($form, $form_state) = ajax_get_form(); @@ -807,9 +808,10 @@ function file_ajax_upload() { 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'); - $commands = array(); - $commands[] = ajax_command_replace(NULL, theme('status_messages')); - return array('#type' => 'ajax', '#commands' => $commands); + $response = new AjaxResponse(); + $response->addCommand(new AjaxCommandReplace(NULL, theme('status_messages'))); + $response->ajaxPrepare(); + return $response; } // Get the current element and count the number of files. @@ -835,16 +837,17 @@ function file_ajax_upload() { else { $form['#suffix'] .= ''; } - $output = theme('status_messages') . drupal_render($form); $js = drupal_add_js(); $settings = call_user_func_array('array_merge_recursive', $js['settings']['data']); - $commands = array(); - $commands[] = ajax_command_replace(NULL, $output, $settings); - return array('#type' => 'ajax', '#commands' => $commands); + $response = new AjaxResponse(); + $response->addCommand(new AjaxCommandReplace(NULL, $output, $settings)); + $response->ajaxPrepare(); + return $response; } + /** * Ajax callback: Retrieves upload progress. *