diff --git a/control/Controller.php b/control/Controller.php index 9ac1db9a5b9..29abfc30cac 100644 --- a/control/Controller.php +++ b/control/Controller.php @@ -127,10 +127,11 @@ public function doInit() { /** * Returns a link to this controller. Overload with your own Link rules if they exist. * + * @param string $action Optional action * @return string */ - public function Link() { - return get_class($this) .'/'; + public function Link($action = null) { + return Controller::join_links(get_class($this), $action, '/'); } /** diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index f205e850333..80f9264418d 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -56,6 +56,7 @@ * `CMSMain::buildbrokenlinks()` action is removed. * `Folder_UnusedAssetsField` is removed. * `UpgradeSiteTreePermissionSchemaTask` is removed. + * `$action` parameter to `Controller::Link()` method is standardised. ## New API diff --git a/tests/control/ControllerTest.php b/tests/control/ControllerTest.php index b398bb90053..b5bc3666337 100644 --- a/tests/control/ControllerTest.php +++ b/tests/control/ControllerTest.php @@ -273,6 +273,14 @@ public function testJoinLinks() { $this->assertEquals("my-page/0", Controller::join_links("my-page", 0)); } + public function testLink() { + $controller = new ControllerTest_HasAction(); + $this->assertEquals('ControllerTest_HasAction/', $controller->Link()); + $this->assertEquals('ControllerTest_HasAction/', $controller->Link(null)); + $this->assertEquals('ControllerTest_HasAction/', $controller->Link(false)); + $this->assertEquals('ControllerTest_HasAction/allowed-action/', $controller->Link('allowed-action')); + } + /** * @covers Controller::hasAction */ diff --git a/tests/forms/MemberDatetimeOptionsetFieldTest.php b/tests/forms/MemberDatetimeOptionsetFieldTest.php index 7aa127726c7..59e5fb0b77a 100644 --- a/tests/forms/MemberDatetimeOptionsetFieldTest.php +++ b/tests/forms/MemberDatetimeOptionsetFieldTest.php @@ -118,8 +118,8 @@ public function testDescriptionTemplate() { } class MemberDatetimeOptionsetFieldTest_Controller extends Controller { - public function Link() { - return 'test'; + public function Link($action = null) { + return Controller::join_links('test', $action, '/'); } } diff --git a/tests/forms/gridfield/GridField_URLHandlerTest.php b/tests/forms/gridfield/GridField_URLHandlerTest.php index 6546689497a..b49a5fa8a75 100644 --- a/tests/forms/gridfield/GridField_URLHandlerTest.php +++ b/tests/forms/gridfield/GridField_URLHandlerTest.php @@ -35,9 +35,6 @@ class GridField_URLHandlerTest_Controller extends Controller implements TestOnly private static $allowed_actions = array('Form'); - public function Link() { - return get_class($this) ."/"; - } public function Form() { $gridConfig = GridFieldConfig::create(); $gridConfig->addComponent(new GridField_URLHandlerTest_Component());