mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-06-28 23:49:27 +02:00
NEW Add support for callable link formatting
This commit is contained in:
parent
cd94e99d89
commit
5b335ad511
|
@ -25,7 +25,8 @@ use SilverStripe\Security\Member;
|
||||||
use SilverStripe\Security\Permission;
|
use SilverStripe\Security\Permission;
|
||||||
use SilverStripe\Security\Security;
|
use SilverStripe\Security\Security;
|
||||||
use SilverStripe\View\ViewableData;
|
use SilverStripe\View\ViewableData;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Control\HTTPRequest;
|
||||||
/**
|
/**
|
||||||
* Base "abstract" class creating reports on your data.
|
* Base "abstract" class creating reports on your data.
|
||||||
*
|
*
|
||||||
|
@ -85,6 +86,8 @@ class Report extends ViewableData
|
||||||
*/
|
*/
|
||||||
protected $sort = 0;
|
protected $sort = 0;
|
||||||
|
|
||||||
|
protected $params = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports which should not be collected and returned in get_reports
|
* Reports which should not be collected and returned in get_reports
|
||||||
*
|
*
|
||||||
|
@ -97,6 +100,15 @@ class Report extends ViewableData
|
||||||
SideReportWrapper::class,
|
SideReportWrapper::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
if (Injector::inst()->has(HTTPRequest::class)) {
|
||||||
|
$this->params = Injector::inst()->get(HTTPRequest::class)->param('filters');
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the title of this report.
|
* Return the title of this report.
|
||||||
*
|
*
|
||||||
|
@ -162,6 +174,11 @@ class Report extends ViewableData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function columns()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the data class for this report
|
* Return the data class for this report
|
||||||
*/
|
*/
|
||||||
|
@ -324,9 +341,7 @@ class Report extends ViewableData
|
||||||
*/
|
*/
|
||||||
public function getReportField()
|
public function getReportField()
|
||||||
{
|
{
|
||||||
// TODO Remove coupling with global state
|
$items = $this->sourceRecords($this->params, null, null);
|
||||||
$params = isset($_REQUEST['filters']) ? $_REQUEST['filters'] : array();
|
|
||||||
$items = $this->sourceRecords($params, null, null);
|
|
||||||
|
|
||||||
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
||||||
|
|
||||||
|
@ -334,7 +349,6 @@ class Report extends ViewableData
|
||||||
new GridFieldPrintButton('buttons-before-left'),
|
new GridFieldPrintButton('buttons-before-left'),
|
||||||
new GridFieldExportButton('buttons-before-left'),
|
new GridFieldExportButton('buttons-before-left'),
|
||||||
new GridFieldToolbarHeader(),
|
new GridFieldToolbarHeader(),
|
||||||
new GridFieldSortableHeader(),
|
|
||||||
new GridFieldDataColumns(),
|
new GridFieldDataColumns(),
|
||||||
new GridFieldPaginator()
|
new GridFieldPaginator()
|
||||||
);
|
);
|
||||||
|
@ -361,18 +375,22 @@ class Report extends ViewableData
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($info['link']) && $info['link']) {
|
if (isset($info['link']) && $info['link']) {
|
||||||
$fieldFormatting[$source] = function ($value, $item) {
|
if (is_callable($info['link'])) {
|
||||||
if ($item instanceof CMSPreviewable) {
|
$fieldFormatting[$source] = $info['link'];
|
||||||
/** @var CMSPreviewable $item */
|
} else {
|
||||||
return sprintf(
|
$fieldFormatting[$source] = function ($value, $item) {
|
||||||
'<a class="grid-field__link-block" href="%s" title="%s">%s</a>',
|
if ($item instanceof CMSPreviewable) {
|
||||||
Convert::raw2att($item->CMSEditLink()),
|
/** @var CMSPreviewable $item */
|
||||||
Convert::raw2att($value),
|
return sprintf(
|
||||||
Convert::raw2xml($value)
|
'<a class="grid-field__link-block" href="%s" title="%s">%s</a>',
|
||||||
);
|
Convert::raw2att($item->CMSEditLink()),
|
||||||
}
|
Convert::raw2att($value),
|
||||||
return $value;
|
Convert::raw2xml($value)
|
||||||
};
|
);
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
|
$displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user