From 772198a7fc4dd289bc1e5fab7238df60145e49b4 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 8 Jun 2017 12:26:53 +1200 Subject: [PATCH] FIX Backlink for upload form redirects to document admin if no page is available --- code/cms/DMSDocumentAddController.php | 14 ++++++++++++-- tests/cms/DMSDocumentAddControllerTest.php | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/code/cms/DMSDocumentAddController.php b/code/cms/DMSDocumentAddController.php index 0fc11f0..93e95bd 100644 --- a/code/cms/DMSDocumentAddController.php +++ b/code/cms/DMSDocumentAddController.php @@ -187,11 +187,21 @@ class DMSDocumentAddController extends LeftAndMain */ public function Backlink() { - if (!$this->getRequest()->getVar('dsid')) { + if (!$this->getRequest()->getVar('dsid') || !$this->currentPageID()) { $modelAdmin = new DMSDocumentAdmin; $modelAdmin->init(); - return $modelAdmin->Link(); + + if ($this->getRequest()->getVar('dsid')) { + return Controller::join_links( + $modelAdmin->Link('DMSDocumentSet'), + 'EditForm/field/DMSDocumentSet/item', + $this->getRequest()->getVar('dsid'), + 'edit' + ); + } + return $modelAdmin->Link('DMSDocumentSet'); } + return Controller::join_links( singleton('CMSPagesController')->Link(), 'edit/EditForm/field/Document%20Sets/item', diff --git a/tests/cms/DMSDocumentAddControllerTest.php b/tests/cms/DMSDocumentAddControllerTest.php index f77e9da..e07f85f 100644 --- a/tests/cms/DMSDocumentAddControllerTest.php +++ b/tests/cms/DMSDocumentAddControllerTest.php @@ -64,12 +64,20 @@ class DMSDocumentAddControllerTest extends FunctionalTest */ public function testBacklink() { + // No page ID and no document set ID $this->assertContains('admin/documents', $this->controller->Backlink()); + // No page ID, has document set ID $request = new SS_HTTPRequest('GET', '/', array('dsid' => 123)); $this->controller->setRequest($request); $this->assertContains('EditForm', $this->controller->Backlink()); $this->assertContains('123', $this->controller->Backlink()); + + // Has page ID and document set ID + $request = new SS_HTTPRequest('GET', '/', array('dsid' => 123, 'ID' => 234)); + $this->controller->setRequest($request); + $this->assertContains('admin/pages', $this->controller->Backlink()); + $this->assertContains('123', $this->controller->Backlink()); } /**