API CHANGE #3724: Unified the Link() method to accept an action parameter.

From: Andrew Short <andrewjshort@gmail.com>

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88495 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew Short 2009-10-11 00:07:16 +00:00 committed by Sam Minnee
parent c1c7973b95
commit f29eceecff
12 changed files with 26 additions and 35 deletions

View File

@ -158,10 +158,11 @@ class RSSFeed extends ViewableData {
/**
* Get the URL of this feed
*
* @param string $action
* @return string Returns the URL of the feed.
*/
function Link() {
return Director::absoluteURL($this->link);
function Link($action = null) {
return Controller::join_links(Director::absoluteURL($this->link), $action);
}
/**

View File

@ -67,8 +67,8 @@ class SOAPModelAccess extends SapphireSoapServer {
),
);
function Link() {
return "soap/v1/";
function Link($action = null) {
return Controller::join_links("soap/v1/", $action);
}
/**

View File

@ -404,13 +404,6 @@ class Controller extends RequestHandler {
return $d;
}
/**
* Returns an absolute link to this controller
*/
function AbsoluteLink() {
return Director::absoluteURL($this->Link());
}
/**
* Returns the currently logged in user
*/

View File

@ -51,8 +51,8 @@ class RedirectorPage extends Page {
* Return the normal link directly to this page. Once you visit this link, a 30x redirection
* will take you to your final destination.
*/
function regularLink() {
return parent::Link();
function regularLink($action = null) {
return parent::Link($action);
}
/**

View File

@ -682,8 +682,8 @@ class ComplexTableField_ItemRequest extends RequestHandler {
'' => 'index',
);
function Link() {
return $this->ctf->Link() . '/item/' . $this->itemID;
function Link($action = null) {
return Controller::join_links($this->ctf->Link(), '/item/', $this->itemID, $action);
}
function __construct($ctf, $itemID) {
@ -997,8 +997,8 @@ class ComplexTableField_Item extends TableListField_Item {
parent::__construct($item, $parent);
}
function Link() {
return $this->parent->Link() . '/item/' . $this->item->ID;
function Link($action = null) {
return Controller::join_links($this->parent->Link(), '/item/', $this->item->ID, $action);
}
function EditLink() {

View File

@ -84,8 +84,8 @@ class FormField extends RequestHandler {
/**
* Return a Link to this field
*/
function Link() {
return Controller::join_links($this->form->FormAction(), 'field/' . $this->name);
function Link($action = null) {
return Controller::join_links($this->form->FormAction(), 'field/' . $this->name, $action);
}
/**

View File

@ -1318,11 +1318,11 @@ class TableListField_Item extends ViewableData {
}
}
function Link() {
function Link($action = null) {
if($this->parent->getForm()) {
$parentUrlParts = parse_url($this->parent->Link());
$queryPart = (isset($parentUrlParts['query'])) ? '?' . $parentUrlParts['query'] : null;
return Controller::join_links($parentUrlParts['path'], 'item', $this->item->ID, $queryPart);
return Controller::join_links($parentUrlParts['path'], 'item', $this->item->ID, $action, $queryPart);
} else {
// allow for instanciation of this FormField outside of a controller/form
// context (e.g. for unit tests)

4
tests/api/RSSFeedTest.php Normal file → Executable file
View File

@ -67,8 +67,8 @@ class RSSFeedTest_ItemA extends ViewableData {
return "ItemA AltContent";
}
function Link() {
return "item-a/";
function Link($action = null) {
return Controller::join_links("item-a/", $action);
}
}

4
tests/forms/FormTest.php Normal file → Executable file
View File

@ -284,8 +284,8 @@ class FormTest_Controller extends Controller {
protected $template = 'BlankPage';
function Link() {
return Controller::join_links('FormTest_Controller', $this->request->latestParam('Action'), $this->request->latestParam('ID'));
function Link($action = null) {
return Controller::join_links('FormTest_Controller', $this->request->latestParam('Action'), $this->request->latestParam('ID'), $action);
}
function Form() {

5
tests/forms/TableFieldTest.php Normal file → Executable file
View File

@ -284,11 +284,10 @@ class TableFieldTest extends SapphireTest {
* Stub controller
*/
class TableFieldTest_Controller extends Controller {
function Link() {
return 'TableFieldTest/';
function Link($action = null) {
return Controller::join_links('TableFieldTest/', $action);
}
}
class TableFieldTest_Object extends DataObject implements TestOnly {
static $has_many = array(
"HasManyRelations" => 'TableFieldTest_HasManyRelation'

4
tests/forms/TableListFieldTest.php Normal file → Executable file
View File

@ -206,8 +206,8 @@ class TableListFieldTest_CsvExport extends DataObject implements TestOnly {
}
class TableListFieldTest_TestController extends Controller {
function Link() {
return "TableListFieldTest_TestController/";
function Link($action = null) {
return Controller::join_links("TableListFieldTest_TestController/", $action);
}
function TestForm() {
$table = new TableListField("Table", "TableListFieldTest_Obj", array(

8
widgets/Widget.php Normal file → Executable file
View File

@ -154,11 +154,9 @@ class Widget_Controller extends Controller {
parent::__construct();
}
function Link() {
return Controller::join_links(
Controller::curr()->Link(),
'widget',
($this->widget) ? $this->widget->ID : null
public function Link($action = null) {
return Controller::curr()->Link (
Controller::join_links('widget', ($this->widget ? $this->widget->ID : null), $action)
);
}