NEW Allow reports to specify breadcrumbs for child reports

This commit is contained in:
Guy Marriott 2018-11-16 15:09:45 +13:00
parent 7d4d7c05e6
commit edecbabe61
No known key found for this signature in database
GPG Key ID: A80F9ACCB86D3DA7
2 changed files with 26 additions and 7 deletions

View File

@ -29,6 +29,7 @@ use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
use SilverStripe\View\ArrayData;
use SilverStripe\View\ViewableData;
/**
@ -464,10 +465,8 @@ class Report extends ViewableData
/**
* Return the name of this report, which
* is used by the templates to render the
* name of the report in the report tree,
* the left hand pane inside ReportAdmin.
* Return the name of this report, which is used by the templates to render the name of the report in the report
* tree, the left hand pane inside ReportAdmin.
*
* @return string
*/
@ -475,4 +474,14 @@ class Report extends ViewableData
{
return $this->title();
}
/**
* Return additional breadcrumbs for this report. Useful when this report is a child of another.
*
* @return ArrayData[]
*/
public function getBreadcrumbs()
{
return [];
}
}

View File

@ -172,11 +172,21 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
// Uses session state for current record otherwise.
$items[0]->Link = singleton('SilverStripe\\Reports\\ReportAdmin')->Link();
if ($this->reportObject) {
if ($report = $this->reportObject) {
$breadcrumbs = $report->getBreadcrumbs();
if (!empty($breadcrumbs)) {
foreach ($breadcrumbs as $crumb) {
$items->push($crumb);
}
}
//build breadcrumb trail to the current report
$items->push(new ArrayData(array(
'Title' => $this->reportObject->title(),
'Link' => Controller::join_links($this->Link(), '?' . http_build_query(array('q' => $this->request->requestVar('q'))))
'Title' => $report->title(),
'Link' => Controller::join_links(
$this->Link(),
'?' . http_build_query(array('q' => $this->request->requestVar('q')))
)
)));
}