Update Batch API to return a JSON response directly from the controller, and from _batch_do().

8.0.x
Larry Garfield 2012-04-13 00:01:33 -05:00
parent 25ea4a1f4a
commit a001caf29f
2 changed files with 9 additions and 2 deletions

View File

@ -14,6 +14,8 @@
* @see batch_get()
*/
use \Symfony\Component\HttpFoundation\JsonResponse;
/**
* Loads a batch from the database.
*
@ -77,7 +79,7 @@ function _batch_page() {
case 'do':
// JavaScript-based progress page callback.
_batch_do();
$output = _batch_do();
break;
case 'do_nojs':
@ -160,7 +162,7 @@ function _batch_do() {
// Perform actual processing.
list($percentage, $message) = _batch_process();
drupal_json_output(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message));
return new JsonResponse(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message));
}
/**

View File

@ -5,6 +5,8 @@
* Admin page callbacks for the system module.
*/
use Symfony\Component\HttpFoundation\Response;
/**
* Menu callback; Provide the administration overview page.
*/
@ -2358,6 +2360,9 @@ function system_batch_page() {
if ($output === FALSE) {
drupal_access_denied();
}
elseif ($output instanceof Response) {
return $output;
}
elseif (isset($output)) {
// Force a page without blocks or messages to
// display a list of collected messages later.