BUGFIX Passing existing SS_HTTPResponse to PjaxResponseNegotiator in LeftAndMain so state like X-Status HTTP headers are retained (fixes #7427)

This commit is contained in:
Ingo Schommer 2012-06-13 00:27:03 +02:00
parent 9b3d3123b6
commit b1d95cffac
2 changed files with 32 additions and 16 deletions

View File

@ -430,20 +430,23 @@ class LeftAndMain extends Controller implements PermissionProvider {
public function getResponseNegotiator() { public function getResponseNegotiator() {
if(!$this->responseNegotiator) { if(!$this->responseNegotiator) {
$controller = $this; $controller = $this;
$this->responseNegotiator = new PjaxResponseNegotiator(array( $this->responseNegotiator = new PjaxResponseNegotiator(
'CurrentForm' => function() use(&$controller) { array(
return $controller->getEditForm()->forTemplate(); 'CurrentForm' => function() use(&$controller) {
}, return $controller->getEditForm()->forTemplate();
'Content' => function() use(&$controller) { },
return $controller->renderWith($controller->getTemplatesWithSuffix('_Content')); 'Content' => function() use(&$controller) {
}, return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
'Breadcrumbs' => function() use (&$controller) { },
return $controller->renderWith('CMSBreadcrumbs'); 'Breadcrumbs' => function() use (&$controller) {
}, return $controller->renderWith('CMSBreadcrumbs');
'default' => function() use(&$controller) { },
return $controller->renderWith($controller->getViewer('show')); 'default' => function() use(&$controller) {
} return $controller->renderWith($controller->getViewer('show'));
)); }
),
$this->response
);
} }
return $this->responseNegotiator; return $this->responseNegotiator;
} }

View File

@ -20,12 +20,25 @@ class PjaxResponseNegotiator {
'default' => array('Director', 'redirectBack'), 'default' => array('Director', 'redirectBack'),
); );
protected $response = null;
/** /**
* @param RequestHandler $controller * @param RequestHandler $controller
* @param SS_HTTPResponse An existing response to reuse (optional)
* @param Array $callbacks * @param Array $callbacks
*/ */
function __construct($callbacks = array()) { function __construct($callbacks = array(), $response = null) {
$this->callbacks = $callbacks; $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 @@ class PjaxResponseNegotiator {
public function respond(SS_HTTPRequest $request, $extraCallbacks = array()) { public function respond(SS_HTTPRequest $request, $extraCallbacks = array()) {
// Prepare the default options and combine with the others // Prepare the default options and combine with the others
$callbacks = array_merge($this->callbacks, $extraCallbacks); $callbacks = array_merge($this->callbacks, $extraCallbacks);
$response = new SS_HTTPResponse(); $response = $this->getResponse();
$responseParts = array(); $responseParts = array();
if($fragmentStr = $request->getHeader('X-Pjax')) { if($fragmentStr = $request->getHeader('X-Pjax')) {