Merge pull request #2100 from creative-commoners/pulls/4.1/extensible-cmsmain-breadcrumbs

NEW Add extension point to CMSMain::Breadcrumbs
This commit is contained in:
Damian Mooyman 2018-02-20 17:46:54 +13:00 committed by GitHub
commit 8929eae604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 25 deletions

View File

@ -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;
} }

View File

@ -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,8 +34,7 @@ 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 //special case for building the breadcrumbs when calling the listchildren Pages ListView action
if ($parentID = $this->getRequest()->getVar('ParentID')) { if ($parentID = $this->getRequest()->getVar('ParentID')) {
$page = SiteTree::get()->byID($parentID); $page = SiteTree::get()->byID($parentID);
@ -59,7 +59,7 @@ class CMSPagesController extends CMSMain
$items->push(new ArrayData($item)); $items->push(new ArrayData($item));
} }
} }
});
return $items; return parent::Breadcrumbs($unlinked);
} }
} }