From 52a234410d9337b812e6b1ef615850c0b3df3f7a Mon Sep 17 00:00:00 2001 From: Guy Marriott Date: Tue, 20 Nov 2018 17:52:48 +1300 Subject: [PATCH] NEW Extracting out the method to determine parameters (filters) for update the report sourceRecords --- code/Report.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/code/Report.php b/code/Report.php index 3a87e659..5eee3d0c 100644 --- a/code/Report.php +++ b/code/Report.php @@ -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; + } }