2011-04-20 22:50:13 +02:00
|
|
|
<?php
|
2011-08-19 02:32:31 +02:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
2016-08-10 06:08:39 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
2018-02-19 05:01:20 +01:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\View\ArrayData;
|
2016-07-22 01:32:32 +02:00
|
|
|
use stdClass;
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
class CMSPagesController extends CMSMain
|
|
|
|
{
|
|
|
|
|
|
|
|
private static $url_segment = 'pages';
|
|
|
|
|
|
|
|
private static $url_rule = '/$Action/$ID/$OtherID';
|
|
|
|
|
|
|
|
private static $url_priority = 40;
|
|
|
|
|
|
|
|
private static $menu_title = 'Pages';
|
|
|
|
|
|
|
|
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
|
|
|
|
|
|
|
|
public function LinkPreview()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isCurrentPage(DataObject $record)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Breadcrumbs($unlinked = false)
|
|
|
|
{
|
2018-02-19 05:01:20 +01:00
|
|
|
$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);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-02-19 05:01:20 +01:00
|
|
|
//build a reversed list of the parent tree
|
2020-04-19 06:18:01 +02:00
|
|
|
$pages = [];
|
2018-02-19 05:01:20 +01:00
|
|
|
while ($page) {
|
|
|
|
array_unshift($pages, $page); //add to start of array so that array is in reverse order
|
|
|
|
$page = $page->Parent;
|
|
|
|
}
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-02-19 05:01:20 +01:00
|
|
|
//turns the title and link of the breadcrumbs into template-friendly variables
|
2020-04-19 06:18:01 +02:00
|
|
|
$params = array_filter([
|
2018-02-19 05:01:20 +01:00
|
|
|
'view' => $this->getRequest()->getVar('view'),
|
|
|
|
'q' => $this->getRequest()->getVar('q')
|
2020-04-19 06:18:01 +02:00
|
|
|
]);
|
2018-02-19 05:01:20 +01:00
|
|
|
foreach ($pages as $page) {
|
|
|
|
$params['ParentID'] = $page->ID;
|
|
|
|
$item = new stdClass();
|
|
|
|
$item->Title = $page->Title;
|
2022-04-13 07:07:59 +02:00
|
|
|
$item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params ?? []));
|
2018-02-19 05:01:20 +01:00
|
|
|
$items->push(new ArrayData($item));
|
|
|
|
}
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2018-02-19 05:01:20 +01:00
|
|
|
});
|
|
|
|
return parent::Breadcrumbs($unlinked);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|