From e5000dd3308026993159bfae461af82d0de5faf3 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 18 Apr 2012 21:14:14 +0200 Subject: [PATCH] MERGE List view breadcrumbs --- code/controllers/CMSPagesController.php | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/code/controllers/CMSPagesController.php b/code/controllers/CMSPagesController.php index eedec09d..1cdfdb88 100644 --- a/code/controllers/CMSPagesController.php +++ b/code/controllers/CMSPagesController.php @@ -26,4 +26,36 @@ class CMSPagesController extends CMSMain { public function isCurrentPage(DataObject $record) { return false; } + + public function Breadcrumbs($unlinked = false) { + $items = parent::Breadcrumbs($unlinked); + + //special case for building the breadcrumbs when calling the listchildren Pages ListView action + if($parentID = $this->request->getVar('ParentID')) { + $page = DataObject::get_by_id('SiteTree', $parentID); + + //build a reversed list of the parent tree + $pages = array(); + while($page) { + array_unshift($pages, $page); //add to start of array so that array is in reverse order + $page = $page->Parent; + } + + //turns the title and link of the breadcrumbs into template-friendly variables + $params = array_filter(array( + 'view' => $this->request->getVar('view'), + 'q' => $this->request->getVar('q') + )); + foreach($pages as $page) { + $params['ParentID'] = $page->ID; + $item = new StdClass(); + $item->Title = $page->Title; + $item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params)); + $items->push(new ArrayData($item)); + } + } + + return $items; + + } }