FIX Backlink for upload form redirects to document admin if no page is available

This commit is contained in:
Robbie Averill 2017-06-08 12:26:53 +12:00
parent c0dee2f1e5
commit 772198a7fc
2 changed files with 20 additions and 2 deletions

View File

@ -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',

View File

@ -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());
}
/**