Skip to content

Commit

Permalink
Merge pull request #5854 from open-sausages/pulls/4.0/controller-link…
Browse files Browse the repository at this point in the history
…-standardise

API Add $action parameter to Controller::Link
  • Loading branch information
Hamish Friedlander committed Aug 2, 2016
2 parents 76dd9b3 + 9188628 commit 18465e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions control/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
}

/**
Expand Down
1 change: 1 addition & 0 deletions docs/en/04_Changelogs/4.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions tests/control/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/forms/MemberDatetimeOptionsetFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
}

}
3 changes: 0 additions & 3 deletions tests/forms/gridfield/GridField_URLHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 18465e7

Please sign in to comment.