diff --git a/src/BulkManager/BulkAction/EditHandler.php b/src/BulkManager/BulkAction/EditHandler.php index ad4fd01..026a0cd 100644 --- a/src/BulkManager/BulkAction/EditHandler.php +++ b/src/BulkManager/BulkAction/EditHandler.php @@ -451,4 +451,52 @@ class EditHandler extends Handler return Controller::curr()->redirect($this->Link('?records[]=' . implode('&records[]=', $ids))); //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; + } } diff --git a/src/BulkManager/BulkAction/Handler.php b/src/BulkManager/BulkAction/Handler.php index c3cb6d2..69be806 100644 --- a/src/BulkManager/BulkAction/Handler.php +++ b/src/BulkManager/BulkAction/Handler.php @@ -40,13 +40,6 @@ class Handler extends RequestHandler */ protected $component; - /** - * Current controller instance. - * - * @var Controller - */ - protected $controller; - /** * Front-end label for this handler's action * @@ -87,13 +80,11 @@ class Handler extends RequestHandler /** * @param GridField $gridField * @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->component = $component; - $this->controller = $controller; parent::__construct(); } @@ -249,54 +240,6 @@ class Handler extends RequestHandler 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. * diff --git a/src/BulkManager/BulkManager.php b/src/BulkManager/BulkManager.php index 426f945..6a7a1da 100644 --- a/src/BulkManager/BulkManager.php +++ b/src/BulkManager/BulkManager.php @@ -349,7 +349,8 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G $actionUrlSegment = $request->shift(); $handlerClass = $this->config['actions'][$actionUrlSegment]; - $handler = Injector::inst()->create($handlerClass, $gridField, $this, $controller); + $controller->pushCurrent(); + $handler = Injector::inst()->create($handlerClass, $gridField, $this); if ($handler) { return $handler->handleRequest($request); diff --git a/src/BulkUploader/BulkUploadHandler.php b/src/BulkUploader/BulkUploadHandler.php index b17e9dd..a6c088b 100644 --- a/src/BulkUploader/BulkUploadHandler.php +++ b/src/BulkUploader/BulkUploadHandler.php @@ -33,13 +33,6 @@ class BulkUploadHandler extends RequestHandler */ protected $component; - /** - * Gridfield Form controller. - * - * @var Controller - */ - protected $controller; - /** * RequestHandler allowed actions. * @@ -65,11 +58,10 @@ class BulkUploadHandler extends RequestHandler * @param GridField_URLHandler $component * @param Controller $controller */ - public function __construct($gridField, $component, $controller) + public function __construct($gridField, $component) { $this->gridField = $gridField; $this->component = $component; - $this->controller = $controller; parent::__construct(); } diff --git a/src/BulkUploader/BulkUploader.php b/src/BulkUploader/BulkUploader.php index 60c1c34..0cb6ac7 100644 --- a/src/BulkUploader/BulkUploader.php +++ b/src/BulkUploader/BulkUploader.php @@ -331,8 +331,8 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler */ public function handleBulkUpload($gridField, $request) { - $controller = $gridField->getForm()->getController(); - $handler = new \Colymba\BulkUpload\BulkUploadHandler($gridField, $this, $controller); + $gridField->getForm()->getController()->pushCurrent(); + $handler = new \Colymba\BulkUpload\BulkUploadHandler($gridField, $this); return $handler->handleRequest($request); }