API Add $action parameter to Controller::Link

This commit is contained in:
Damian Mooyman 2016-07-29 11:22:03 +12:00
parent 59bba54b30
commit 9188628ae3
5 changed files with 14 additions and 7 deletions

View File

@ -127,10 +127,11 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
/** /**
* Returns a link to this controller. Overload with your own Link rules if they exist. * Returns a link to this controller. Overload with your own Link rules if they exist.
* *
* @param string $action Optional action
* @return string * @return string
*/ */
public function Link() { public function Link($action = null) {
return get_class($this) .'/'; return Controller::join_links(get_class($this), $action, '/');
} }
/** /**

View File

@ -56,6 +56,7 @@
* `CMSMain::buildbrokenlinks()` action is removed. * `CMSMain::buildbrokenlinks()` action is removed.
* `Folder_UnusedAssetsField` is removed. * `Folder_UnusedAssetsField` is removed.
* `UpgradeSiteTreePermissionSchemaTask` is removed. * `UpgradeSiteTreePermissionSchemaTask` is removed.
* `$action` parameter to `Controller::Link()` method is standardised.
## New API ## New API

View File

@ -273,6 +273,14 @@ class ControllerTest extends FunctionalTest {
$this->assertEquals("my-page/0", Controller::join_links("my-page", 0)); $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 * @covers Controller::hasAction
*/ */

View File

@ -118,8 +118,8 @@ class MemberDatetimeOptionsetFieldTest extends SapphireTest {
} }
class MemberDatetimeOptionsetFieldTest_Controller extends Controller { class MemberDatetimeOptionsetFieldTest_Controller extends Controller {
public function Link() { public function Link($action = null) {
return 'test'; return Controller::join_links('test', $action, '/');
} }
} }

View File

@ -35,9 +35,6 @@ class GridField_URLHandlerTest_Controller extends Controller implements TestOnly
private static $allowed_actions = array('Form'); private static $allowed_actions = array('Form');
public function Link() {
return get_class($this) ."/";
}
public function Form() { public function Form() {
$gridConfig = GridFieldConfig::create(); $gridConfig = GridFieldConfig::create();
$gridConfig->addComponent(new GridField_URLHandlerTest_Component()); $gridConfig->addComponent(new GridField_URLHandlerTest_Component());