API Controller is not passed to handler as param

instead we use pushCurrent to set it as current controller
This commit is contained in:
Thierry François 2018-03-11 12:37:50 +02:00
parent 482139fd35
commit a1dcbc00e6
5 changed files with 54 additions and 70 deletions

View File

@ -451,4 +451,52 @@ class EditHandler extends Handler
return Controller::curr()->redirect($this->Link('?records[]=' . implode('&records[]=', $ids))); return Controller::curr()->redirect($this->Link('?records[]=' . implode('&records[]=', $ids)));
//return Controller::curr()->redirect($form->Backlink); //returns to gridField //return Controller::curr()->redirect($form->Backlink); //returns to gridField
} }
/**
* Traverse up nested requests until we reach the first that's not a GridFieldDetailForm or GridFieldDetailForm_ItemRequest.
* The opposite of {@link Controller::curr()}, required because
* Controller::$controller_stack is not directly accessible.
*
* @return Controller
*/
protected function getToplevelController()
{
$c = Controller::curr();
while ($c && ($c instanceof GridFieldDetailForm_ItemRequest || $c instanceof GridFieldDetailForm)) {
$c = $c->getController();
}
return $c;
}
/**
* Edited version of the GridFieldEditForm function
* adds the 'Bulk Upload' at the end of the crums.
*
* CMS-specific functionality: Passes through navigation breadcrumbs
* to the template, and includes the currently edited record (if any).
* see {@link LeftAndMain->Breadcrumbs()} for details.
*
* @author SilverStripe original Breadcrumbs() method
*
* @see GridFieldDetailForm_ItemRequest
*
* @param bool $unlinked
*
* @return ArrayData
*/
public function Breadcrumbs($unlinked = false)
{
if (!Controller::curr()->hasMethod('Breadcrumbs')) {
return;
}
$items = Controller::curr()->Breadcrumbs($unlinked);
$items->push(new ArrayData(array(
'Title' => 'Bulk Editing',
'Link' => false,
)));
return $items;
}
} }

View File

@ -40,13 +40,6 @@ class Handler extends RequestHandler
*/ */
protected $component; protected $component;
/**
* Current controller instance.
*
* @var Controller
*/
protected $controller;
/** /**
* Front-end label for this handler's action * Front-end label for this handler's action
* *
@ -87,13 +80,11 @@ class Handler extends RequestHandler
/** /**
* @param GridField $gridField * @param GridField $gridField
* @param GridField_URLHandler $component * @param GridField_URLHandler $component
* @param Controller $controller
*/ */
public function __construct($gridField = null, $component = null, $controller = null) public function __construct($gridField = null, $component = null)
{ {
$this->gridField = $gridField; $this->gridField = $gridField;
$this->component = $component; $this->component = $component;
$this->controller = $controller;
parent::__construct(); parent::__construct();
} }
@ -249,54 +240,6 @@ class Handler extends RequestHandler
return Controller::join_links($this->gridField->Link(), 'bulkAction', $action); return Controller::join_links($this->gridField->Link(), 'bulkAction', $action);
} }
/**
* Traverse up nested requests until we reach the first that's not a GridFieldDetailForm or GridFieldDetailForm_ItemRequest.
* The opposite of {@link Controller::curr()}, required because
* Controller::$controller_stack is not directly accessible.
*
* @return Controller
*/
protected function getToplevelController()
{
$c = $this->controller;
while ($c && ($c instanceof GridFieldDetailForm_ItemRequest || $c instanceof GridFieldDetailForm)) {
$c = $c->getController();
}
return $c;
}
/**
* Edited version of the GridFieldEditForm function
* adds the 'Bulk Upload' at the end of the crums.
*
* CMS-specific functionality: Passes through navigation breadcrumbs
* to the template, and includes the currently edited record (if any).
* see {@link LeftAndMain->Breadcrumbs()} for details.
*
* @author SilverStripe original Breadcrumbs() method
*
* @see GridFieldDetailForm_ItemRequest
*
* @param bool $unlinked
*
* @return ArrayData
*/
public function Breadcrumbs($unlinked = false)
{
if (!$this->controller->hasMethod('Breadcrumbs')) {
return;
}
$items = $this->controller->Breadcrumbs($unlinked);
$items->push(new ArrayData(array(
'Title' => 'Bulk Editing',
'Link' => false,
)));
return $items;
}
/** /**
* Returns the list of record IDs selected in the front-end. * Returns the list of record IDs selected in the front-end.
* *

View File

@ -349,7 +349,8 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
$actionUrlSegment = $request->shift(); $actionUrlSegment = $request->shift();
$handlerClass = $this->config['actions'][$actionUrlSegment]; $handlerClass = $this->config['actions'][$actionUrlSegment];
$handler = Injector::inst()->create($handlerClass, $gridField, $this, $controller); $controller->pushCurrent();
$handler = Injector::inst()->create($handlerClass, $gridField, $this);
if ($handler) if ($handler)
{ {
return $handler->handleRequest($request); return $handler->handleRequest($request);

View File

@ -33,13 +33,6 @@ class BulkUploadHandler extends RequestHandler
*/ */
protected $component; protected $component;
/**
* Gridfield Form controller.
*
* @var Controller
*/
protected $controller;
/** /**
* RequestHandler allowed actions. * RequestHandler allowed actions.
* *
@ -65,11 +58,10 @@ class BulkUploadHandler extends RequestHandler
* @param GridField_URLHandler $component * @param GridField_URLHandler $component
* @param Controller $controller * @param Controller $controller
*/ */
public function __construct($gridField, $component, $controller) public function __construct($gridField, $component)
{ {
$this->gridField = $gridField; $this->gridField = $gridField;
$this->component = $component; $this->component = $component;
$this->controller = $controller;
parent::__construct(); parent::__construct();
} }

View File

@ -331,8 +331,8 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
*/ */
public function handleBulkUpload($gridField, $request) public function handleBulkUpload($gridField, $request)
{ {
$controller = $gridField->getForm()->getController(); $gridField->getForm()->getController()->pushCurrent();
$handler = new \Colymba\BulkUpload\BulkUploadHandler($gridField, $this, $controller); $handler = new \Colymba\BulkUpload\BulkUploadHandler($gridField, $this);
return $handler->handleRequest($request); return $handler->handleRequest($request);
} }