diff --git a/code/cms/DMSDocumentAddController.php b/code/cms/DMSDocumentAddController.php index 42b0a95..5c62a45 100644 --- a/code/cms/DMSDocumentAddController.php +++ b/code/cms/DMSDocumentAddController.php @@ -197,10 +197,26 @@ class DMSDocumentAddController extends LeftAndMain return $modelAdmin->Link(); } + return $this->getPageEditLink($this->currentPageID(), $this->getRequest()->getVar('dsid')); + } + + /** + * Return a link to a page. In SS <= 3.5 this is loaded from the session, whereas in SS >= 3.6 this is set + * explicitly to a class property on CMSMain. This method checks whether the URL handler to detect this ID + * exists on CMSMain, if so include it in the URL. + * + * @param int $pageId + * @param int $documentSetId + * @return string + */ + protected function getPageEditLink($pageId, $documentSetId) + { + // Only get configuration from CMSMain, not its descendants or extensions + $urlHandlers = (array) Config::inst()->get('CMSMain', 'url_handlers', Config::UNINHERITED); + $pageIdSegment = array_key_exists('EditForm/$ID', $urlHandlers) ? $pageId . '/' : ''; return Controller::join_links( singleton('CMSPagesController')->Link(), - 'edit/EditForm/field/Document%20Sets/item', - $this->getRequest()->getVar('dsid') + sprintf('edit/EditForm/%sfield/Document Sets/item/%d', $pageIdSegment, $documentSetId) ); } diff --git a/tests/cms/DMSDocumentAddControllerTest.php b/tests/cms/DMSDocumentAddControllerTest.php index a88eb01..3fee715 100644 --- a/tests/cms/DMSDocumentAddControllerTest.php +++ b/tests/cms/DMSDocumentAddControllerTest.php @@ -78,6 +78,15 @@ class DMSDocumentAddControllerTest extends FunctionalTest $this->controller->setRequest($request); $this->assertContains('admin/pages', $this->controller->Backlink()); $this->assertContains('123', $this->controller->Backlink()); + + $urlHandlers = (array) Config::inst()->get('CMSMain', 'url_handlers', Config::UNINHERITED); + if (array_key_exists('EditForm/$ID', $urlHandlers)) { + // SS 3.6 and above, ensure that the page ID is in the edit URL + $this->assertContains('admin/pages/edit/EditForm/234', $this->controller->Backlink()); + } else { + // SS 3.5 and below, the page ID is loaded from the session + $this->assertNotContains('234', $this->controller->Backlink()); + } } /**