Skip to content

Commit

Permalink
BUGFIX Passing existing SS_HTTPResponse to PjaxResponseNegotiator in …
Browse files Browse the repository at this point in the history
…LeftAndMain so state like X-Status HTTP headers are retained (fixes #7427)
  • Loading branch information
chillu committed Jun 12, 2012
1 parent 9b3d312 commit b1d95cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
31 changes: 17 additions & 14 deletions admin/code/LeftAndMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 15 additions & 2 deletions control/PjaxResponseNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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')) {
Expand Down

0 comments on commit b1d95cf

Please sign in to comment.