From f29eceecff2cf4cbe623baa18facabcb72bf23a5 Mon Sep 17 00:00:00 2001 From: Andrew Short Date: Sun, 11 Oct 2009 00:07:16 +0000 Subject: [PATCH] API CHANGE #3724: Unified the Link() method to accept an action parameter. From: Andrew Short git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88495 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- api/RSSFeed.php | 5 +++-- api/SOAPModelAccess.php | 4 ++-- core/control/Controller.php | 7 ------- core/model/RedirectorPage.php | 4 ++-- forms/ComplexTableField.php | 8 ++++---- forms/FormField.php | 4 ++-- forms/TableListField.php | 4 ++-- tests/api/RSSFeedTest.php | 4 ++-- tests/forms/FormTest.php | 4 ++-- tests/forms/TableFieldTest.php | 5 ++--- tests/forms/TableListFieldTest.php | 4 ++-- widgets/Widget.php | 8 +++----- 12 files changed, 26 insertions(+), 35 deletions(-) mode change 100644 => 100755 tests/api/RSSFeedTest.php mode change 100644 => 100755 tests/forms/FormTest.php mode change 100644 => 100755 tests/forms/TableFieldTest.php mode change 100644 => 100755 tests/forms/TableListFieldTest.php mode change 100644 => 100755 widgets/Widget.php diff --git a/api/RSSFeed.php b/api/RSSFeed.php index a5d23eba9..69e4558aa 100755 --- a/api/RSSFeed.php +++ b/api/RSSFeed.php @@ -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); } /** diff --git a/api/SOAPModelAccess.php b/api/SOAPModelAccess.php index d8ba49fbf..a326aa530 100755 --- a/api/SOAPModelAccess.php +++ b/api/SOAPModelAccess.php @@ -67,8 +67,8 @@ class SOAPModelAccess extends SapphireSoapServer { ), ); - function Link() { - return "soap/v1/"; + function Link($action = null) { + return Controller::join_links("soap/v1/", $action); } /** diff --git a/core/control/Controller.php b/core/control/Controller.php index 3e69b5877..e6960bee8 100755 --- a/core/control/Controller.php +++ b/core/control/Controller.php @@ -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 */ diff --git a/core/model/RedirectorPage.php b/core/model/RedirectorPage.php index ee6552c8c..e0b6498f9 100755 --- a/core/model/RedirectorPage.php +++ b/core/model/RedirectorPage.php @@ -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); } /** diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index 2f657d3d4..5c2e5fe61 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -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() { diff --git a/forms/FormField.php b/forms/FormField.php index 8ffec80b1..7647b2c32 100755 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -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); } /** diff --git a/forms/TableListField.php b/forms/TableListField.php index 5b543187c..fa9da7581 100755 --- a/forms/TableListField.php +++ b/forms/TableListField.php @@ -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) diff --git a/tests/api/RSSFeedTest.php b/tests/api/RSSFeedTest.php old mode 100644 new mode 100755 index aece8750d..517b26379 --- a/tests/api/RSSFeedTest.php +++ b/tests/api/RSSFeedTest.php @@ -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); } } diff --git a/tests/forms/FormTest.php b/tests/forms/FormTest.php old mode 100644 new mode 100755 index dc1b145ef..071983609 --- a/tests/forms/FormTest.php +++ b/tests/forms/FormTest.php @@ -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() { diff --git a/tests/forms/TableFieldTest.php b/tests/forms/TableFieldTest.php old mode 100644 new mode 100755 index dd9d744df..1d02836f6 --- a/tests/forms/TableFieldTest.php +++ b/tests/forms/TableFieldTest.php @@ -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' diff --git a/tests/forms/TableListFieldTest.php b/tests/forms/TableListFieldTest.php old mode 100644 new mode 100755 index d8950943e..80e3e7cfe --- a/tests/forms/TableListFieldTest.php +++ b/tests/forms/TableListFieldTest.php @@ -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( diff --git a/widgets/Widget.php b/widgets/Widget.php old mode 100644 new mode 100755 index 7eef7a543..965798778 --- a/widgets/Widget.php +++ b/widgets/Widget.php @@ -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) ); }