Permalink
Browse files

BUGFIX Passing existing SS_HTTPResponse to PjaxResponseNegotiator in …

…LeftAndMain so state like X-Status HTTP headers are retained (fixes #7427)
  • Loading branch information...
1 parent 9b3d312 commit b1d95cffac391d1a4d539d6d91d43aa1af2d17eb @chillu chillu committed Jun 12, 2012
Showing with 32 additions and 16 deletions.
  1. +17 −14 admin/code/LeftAndMain.php
  2. +15 −2 control/PjaxResponseNegotiator.php
@@ -430,20 +430,23 @@ public function show($request) {
public function getResponseNegotiator() {
if(!$this->responseNegotiator) {
$controller = $this;
- $this->responseNegotiator = new PjaxResponseNegotiator(array(
- 'CurrentForm' => function() use(&$controller) {
- return $controller->getEditForm()->forTemplate();
- },
- 'Content' => function() use(&$controller) {
- return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
- },
- 'Breadcrumbs' => function() use (&$controller) {
- return $controller->renderWith('CMSBreadcrumbs');
- },
- 'default' => function() use(&$controller) {
- return $controller->renderWith($controller->getViewer('show'));
- }
- ));
+ $this->responseNegotiator = new PjaxResponseNegotiator(
+ array(
+ 'CurrentForm' => function() use(&$controller) {
+ return $controller->getEditForm()->forTemplate();
+ },
+ 'Content' => function() use(&$controller) {
+ return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
+ },
+ 'Breadcrumbs' => function() use (&$controller) {
+ return $controller->renderWith('CMSBreadcrumbs');
+ },
+ 'default' => function() use(&$controller) {
+ return $controller->renderWith($controller->getViewer('show'));
+ }
+ ),
+ $this->response
+ );
}
return $this->responseNegotiator;
}
@@ -20,12 +20,25 @@ class PjaxResponseNegotiator {
'default' => array('Director', 'redirectBack'),
);
+ protected $response = null;
+
/**
* @param RequestHandler $controller
+ * @param SS_HTTPResponse An existing response to reuse (optional)
* @param Array $callbacks
*/
- function __construct($callbacks = array()) {
+ function __construct($callbacks = array(), $response = null) {
$this->callbacks = $callbacks;
+ $this->response = $response;
+ }
+
+ public function getResponse() {
+ if(!$this->response) $this->response = new SS_HTTPResponse();
+ return $this->response;
+ }
+
+ public function setResponse($response) {
+ $this->response = $response;
}
/**
@@ -41,7 +54,7 @@ function __construct($callbacks = array()) {
public function respond(SS_HTTPRequest $request, $extraCallbacks = array()) {
// Prepare the default options and combine with the others
$callbacks = array_merge($this->callbacks, $extraCallbacks);
- $response = new SS_HTTPResponse();
+ $response = $this->getResponse();
$responseParts = array();
if($fragmentStr = $request->getHeader('X-Pjax')) {

0 comments on commit b1d95cf

Please sign in to comment.