From 9d31bb0542d1d3913be7c3aa12f88d9498847e48 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 1 Aug 2016 16:35:37 +1200 Subject: [PATCH] BUG Fix broken form actions on parent and nested gridfields --- code/Report.php | 4 ++-- code/ReportAdmin.php | 41 +++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/code/Report.php b/code/Report.php index e27d7f24..b922d960 100644 --- a/code/Report.php +++ b/code/Report.php @@ -158,9 +158,9 @@ public function dataClass() public function getLink($action = null) { + return Controller::join_links( - AdminRootController::admin_url(), - Config::inst()->get('ReportAdmin', 'url_segment'), + ReportAdmin::singleton()->Link('show'), get_class($this), $action ); diff --git a/code/ReportAdmin.php b/code/ReportAdmin.php index ef4497b3..297e9c7a 100644 --- a/code/ReportAdmin.php +++ b/code/ReportAdmin.php @@ -18,11 +18,8 @@ */ class ReportAdmin extends LeftAndMain implements PermissionProvider { - private static $url_segment = 'reports'; - private static $url_rule = '/$ReportClass/$Action'; - private static $menu_title = 'Reports'; private static $template_path = null; // defaults to (project)/templates/email @@ -30,7 +27,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider private static $tree_class = 'SS_Report'; private static $url_handlers = array( - '$ReportClass/$Action' => 'handleAction' + 'show/$ReportClass/$Action' => 'handleAction' ); /** @@ -50,13 +47,6 @@ public function init() { parent::init(); - //set the report we are currently viewing from the URL - $this->reportClass = (isset($this->urlParams['ReportClass']) && $this->urlParams['ReportClass'] !== 'index') - ? $this->urlParams['ReportClass'] - : null; - $allReports = SS_Report::get_reports(); - $this->reportObject = (isset($allReports[$this->reportClass])) ? $allReports[$this->reportClass] : null; - // Set custom options for TinyMCE specific to ReportAdmin HTMLEditorConfig::get('cms')->setOption('content_css', project() . '/css/editor.css'); HTMLEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang()); @@ -111,6 +101,22 @@ public function Reports() return $output; } + public function handleAction($request, $action) { + $this->reportClass = $request->param('ReportClass'); + + // Check report + if ($this->reportClass) { + $allReports = SS_Report::get_reports(); + if (empty($allReports[$this->reportClass])) { + return $this->httpError(404); + } + $this->reportObject = $allReports[$this->reportClass]; + } + + // Delegate to sub-form + return parent::handleAction($request, $action); + } + /** * Determine if we have reports and need * to display the "Reports" main menu item @@ -142,9 +148,9 @@ public function Breadcrumbs($unlinked = false) if ($this->reportObject) { //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' => $this->reportObject->title(), + 'Link' => Controller::join_links($this->Link(), '?' . http_build_query(array('q' => $this->request->requestVar('q')))) + ))); } return $items; @@ -162,13 +168,8 @@ public function Link($action = null) return $this->reportObject->getLink($action); } - // Join parent action - if($action) { - return static::join_links(parent::Link('index'), $action); - } - // Basic link to this cms section - return parent::Link(); + return parent::Link($action); } public function providePermissions()