mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
NEW Add extension point to CMSMain::Breadcrumbs
This commit is contained in:
parent
319a46087d
commit
9ebea37b33
@ -992,6 +992,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
'Title' => CMSPagesController::menu_title(),
|
'Title' => CMSPagesController::menu_title(),
|
||||||
'Link' => ($unlinked) ? false : $this->LinkPages()
|
'Link' => ($unlinked) ? false : $this->LinkPages()
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
$this->extend('updateBreadcrumbs', $items);
|
||||||
|
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,6 +1012,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->extend('updateBreadcrumbs', $items);
|
||||||
|
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ namespace SilverStripe\CMS\Controllers;
|
|||||||
|
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
@ -33,33 +34,32 @@ class CMSPagesController extends CMSMain
|
|||||||
|
|
||||||
public function Breadcrumbs($unlinked = false)
|
public function Breadcrumbs($unlinked = false)
|
||||||
{
|
{
|
||||||
$items = parent::Breadcrumbs($unlinked);
|
$this->beforeExtending('updateBreadcrumbs', function (ArrayList $items) {
|
||||||
|
//special case for building the breadcrumbs when calling the listchildren Pages ListView action
|
||||||
|
if ($parentID = $this->getRequest()->getVar('ParentID')) {
|
||||||
|
$page = SiteTree::get()->byID($parentID);
|
||||||
|
|
||||||
//special case for building the breadcrumbs when calling the listchildren Pages ListView action
|
//build a reversed list of the parent tree
|
||||||
if ($parentID = $this->getRequest()->getVar('ParentID')) {
|
$pages = array();
|
||||||
$page = SiteTree::get()->byID($parentID);
|
while ($page) {
|
||||||
|
array_unshift($pages, $page); //add to start of array so that array is in reverse order
|
||||||
|
$page = $page->Parent;
|
||||||
|
}
|
||||||
|
|
||||||
//build a reversed list of the parent tree
|
//turns the title and link of the breadcrumbs into template-friendly variables
|
||||||
$pages = array();
|
$params = array_filter(array(
|
||||||
while ($page) {
|
'view' => $this->getRequest()->getVar('view'),
|
||||||
array_unshift($pages, $page); //add to start of array so that array is in reverse order
|
'q' => $this->getRequest()->getVar('q')
|
||||||
$page = $page->Parent;
|
));
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
//turns the title and link of the breadcrumbs into template-friendly variables
|
return parent::Breadcrumbs($unlinked);
|
||||||
$params = array_filter(array(
|
|
||||||
'view' => $this->getRequest()->getVar('view'),
|
|
||||||
'q' => $this->getRequest()->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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user