Merge pull request #5854 from open-sausages/pulls/4.0/controller-link-standardise

API Add $action parameter to Controller::Link
This commit is contained in:
Hamish Friedlander 2016-08-02 16:42:25 +12:00 committed by GitHub
commit 18465e783f
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.
*
* @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, '/');
}
/**

View File

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

View File

@ -273,6 +273,14 @@ class ControllerTest extends FunctionalTest {
$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
*/

View File

@ -118,8 +118,8 @@ class MemberDatetimeOptionsetFieldTest extends SapphireTest {
}
class MemberDatetimeOptionsetFieldTest_Controller extends Controller {
public function Link() {
return 'test';
public function Link($action = null) {
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');
public function Link() {
return get_class($this) ."/";
}
public function Form() {
$gridConfig = GridFieldConfig::create();
$gridConfig->addComponent(new GridField_URLHandlerTest_Component());