NEW Extracting out the method to determine parameters (filters) for update the report sourceRecords

This commit is contained in:
Guy Marriott 2018-11-20 17:52:48 +13:00
parent d6b1c071b6
commit 52a234410d
No known key found for this signature in database
GPG Key ID: A80F9ACCB86D3DA7

View File

@ -346,12 +346,7 @@ class Report extends ViewableData
*/
public function getReportField()
{
$params = [];
if (Injector::inst()->has(HTTPRequest::class)) {
/** @var HTTPRequest $request */
$request = Injector::inst()->get(HTTPRequest::class);
$params = $request->param('filters') ?: $request->requestVar('filters') ?: [];
}
$params = $this->getSourceParams();
$items = $this->sourceRecords($params, null, null);
$gridFieldConfig = GridFieldConfig::create()->addComponents(
@ -484,4 +479,23 @@ class Report extends ViewableData
{
return [];
}
/**
* Get source params for the report to filter by
*
* @return array
*/
protected function getSourceParams()
{
$params = [];
if (Injector::inst()->has(HTTPRequest::class)) {
/** @var HTTPRequest $request */
$request = Injector::inst()->get(HTTPRequest::class);
$params = $request->param('filters') ?: $request->requestVar('filters') ?: [];
}
$this->extend('updateSourceParams', $params);
return $params;
}
}