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\Member;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\View\ArrayData;
use SilverStripe\View\ViewableData; use SilverStripe\View\ViewableData;
/** /**
@ -464,10 +465,8 @@ class Report extends ViewableData
/** /**
* Return the name of this report, which * Return the name of this report, which is used by the templates to render the name of the report in the report
* is used by the templates to render the * tree, the left hand pane inside ReportAdmin.
* name of the report in the report tree,
* the left hand pane inside ReportAdmin.
* *
* @return string * @return string
*/ */
@ -475,4 +474,14 @@ class Report extends ViewableData
{ {
return $this->title(); 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. // Uses session state for current record otherwise.
$items[0]->Link = singleton('SilverStripe\\Reports\\ReportAdmin')->Link(); $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 //build breadcrumb trail to the current report
$items->push(new ArrayData(array( $items->push(new ArrayData(array(
'Title' => $this->reportObject->title(), 'Title' => $report->title(),
'Link' => Controller::join_links($this->Link(), '?' . http_build_query(array('q' => $this->request->requestVar('q')))) 'Link' => Controller::join_links(
$this->Link(),
'?' . http_build_query(array('q' => $this->request->requestVar('q')))
)
))); )));
} }