From b1d95cffac391d1a4d539d6d91d43aa1af2d17eb Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 13 Jun 2012 00:27:03 +0200 Subject: [PATCH] BUGFIX Passing existing SS_HTTPResponse to PjaxResponseNegotiator in LeftAndMain so state like X-Status HTTP headers are retained (fixes #7427) --- admin/code/LeftAndMain.php | 31 ++++++++++++++++-------------- control/PjaxResponseNegotiator.php | 17 ++++++++++++++-- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index 4e92a92d7..bdb4621d8 100644 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -430,20 +430,23 @@ class LeftAndMain extends Controller implements PermissionProvider { 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; } diff --git a/control/PjaxResponseNegotiator.php b/control/PjaxResponseNegotiator.php index 71c852b32..2aabeaef4 100644 --- a/control/PjaxResponseNegotiator.php +++ b/control/PjaxResponseNegotiator.php @@ -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 @@ class PjaxResponseNegotiator { 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')) {