Skip to content

Commit

Permalink
Merge pull request #167 from creative-commoners/pulls/2.0/fix-backlin…
Browse files Browse the repository at this point in the history
…k-for-documentadmin

FIX Backlink for upload form redirects to document admin if no page is available
  • Loading branch information
sachajudd committed Jun 8, 2017
2 parents c0dee2f + 772198a commit b0de8b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 12 additions & 2 deletions code/cms/DMSDocumentAddController.php
Expand Up @@ -187,11 +187,21 @@ public function Breadcrumbs($unlinked = false)
*/
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',
Expand Down
8 changes: 8 additions & 0 deletions tests/cms/DMSDocumentAddControllerTest.php
Expand Up @@ -64,12 +64,20 @@ public function testGetAllowedExtensions()
*/
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());
}

/**
Expand Down

0 comments on commit b0de8b3

Please sign in to comment.