Skip to content

Commit

Permalink
Align AJAX logic: merge custom response last
Browse files Browse the repository at this point in the history
This is to allow overriding the standard values
Refs octobercms#2209
  • Loading branch information
daftspunk committed Jul 16, 2016
1 parent 09adbbe commit e970d80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modules/backend/classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ protected function execAjaxHandlers()
if ($this->hasAssetsDefined()) {
$responseContents['X_OCTOBER_ASSETS'] = $this->getAssetPaths();
}

/*
* If the handler returned an array, we should add it to output for rendering.
* If it is a string, add it to the array with the key "result".
Expand Down
22 changes: 11 additions & 11 deletions modules/cms/classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,17 +630,6 @@ protected function execAjaxHandlers()
throw new CmsException(Lang::get('cms::lang.ajax_handler.not_found', ['name'=>$handler]));
}

/*
* If the handler returned an array, we should add it to output for rendering.
* If it is a string, add it to the array with the key "result".
*/
if (is_array($result)) {
$responseContents = array_merge($responseContents, $result);
}
elseif (is_string($result)) {
$responseContents['result'] = $result;
}

/*
* Render partials and return the response as array that will be converted to JSON automatically.
*/
Expand All @@ -656,6 +645,17 @@ protected function execAjaxHandlers()
$responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl();
}

/*
* If the handler returned an array, we should add it to output for rendering.
* If it is a string, add it to the array with the key "result".
*/
if (is_array($result)) {
$responseContents = array_merge($responseContents, $result);
}
elseif (is_string($result)) {
$responseContents['result'] = $result;
}

return Response::make($responseContents, $this->statusCode);
}
catch (ValidationException $ex) {
Expand Down

0 comments on commit e970d80

Please sign in to comment.