BUGFIX: Use Controller::join_links() for all TableListField and ComplexTableField link building, to support form URLs with querystrings.

BUGFIX: If ComplexTableField::getParentRecord() can't find a record, just return null rather than erroring. (from r96555) (from r96649)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96775 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-01-12 23:45:24 +00:00
parent 252fbf0ba7
commit 9f9c572306
3 changed files with 17 additions and 13 deletions

View File

@ -354,7 +354,7 @@ JS;
function AddLink() { function AddLink() {
return $this->Link() . '/add'; return Controller::join_links($this->Link(), 'add');
} }
/** /**
@ -390,16 +390,18 @@ JS;
} }
/** /**
* Return the record in which the CTF resides * Return the record in which the CTF resides, if it exists.
*/ */
function getParentRecord() { function getParentRecord() {
if($this->form && $record = $this->form->getRecord()) { if($this->form && $record = $this->form->getRecord()) {
return $record; return $record;
} else { } else {
if($this->sourceID()) { $parentID = (int)$this->sourceID();
$parentClass = DataObject::get_by_id($this->getParentClass(), $this->sourceID()); $parentClass = $this->getParentClass();
} else {
$parentClass = singleton($this->getParentClass()); if($parentClass) {
if($parentID) return DataObject::get_by_id($parentClass, $parentID);
else return singleton($parentClass);
} }
} }
} }
@ -660,10 +662,12 @@ JS;
_t('ComplexTableField.CLOSEPOPUP', 'Close Popup') _t('ComplexTableField.CLOSEPOPUP', 'Close Popup')
); );
$editLink = Controller::join_links($this->Link(), 'item/' . $childData->ID . '/edit');
$message = sprintf( $message = sprintf(
_t('ComplexTableField.SUCCESSADD', 'Added %s %s %s'), _t('ComplexTableField.SUCCESSADD', 'Added %s %s %s'),
$childData->singular_name(), $childData->singular_name(),
'<a href="' . $this->Link() . '/item/' . $childData->ID . '/edit">' . $childData->Title . '</a>', '<a href="' . $editLink . '">' . $childData->Title . '</a>',
$closeLink $closeLink
); );
@ -1007,15 +1011,15 @@ class ComplexTableField_Item extends TableListField_Item {
} }
function EditLink() { function EditLink() {
return $this->Link() . "/edit"; return Controller::join_links($this->Link(), "edit");
} }
function ShowLink() { function ShowLink() {
return $this->Link() . "/show"; return Controller::join_links($this->Link(), "show");
} }
function DeleteLink() { function DeleteLink() {
return $this->Link() . "/delete"; return Controller::join_links($this->Link(), "delete");
} }
/** /**

View File

@ -1124,7 +1124,7 @@ JS
if(isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) { if(isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) {
$start = ($_REQUEST['ctf'][$this->Name()]['start'] < 0) ? 0 : $_REQUEST['ctf'][$this->Name()]['start']; $start = ($_REQUEST['ctf'][$this->Name()]['start'] < 0) ? 0 : $_REQUEST['ctf'][$this->Name()]['start'];
$link .= "/?ctf[{$this->Name()}][start]={$start}"; $link = Controller::join_links($link, "?ctf[{$this->Name()}][start]={$start}");
} }
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams); if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
@ -1417,7 +1417,7 @@ class TableListField_ItemRequest extends RequestHandler {
); );
function Link() { function Link() {
return $this->ctf->Link() . '/item/' . $this->itemID; return Controller::join_links($this->ctf->Link(), 'item/' . $this->itemID);
} }
function __construct($ctf, $itemID) { function __construct($ctf, $itemID) {

View File

@ -95,7 +95,7 @@ ComplexTableField.prototype = {
var table = Event.findElement(e,"table"); var table = Event.findElement(e,"table");
if(Event.element(e).nodeName == "IMG") { if(Event.element(e).nodeName == "IMG") {
link = Event.findElement(e,"a"); link = Event.findElement(e,"a");
popupLink = link.href+"?ajax=1"; popupLink = link.href + (link.href.match(/\?/) ? "&ajax=1" : "?ajax=1");
} else { } else {
el = Event.findElement(e,"tr"); el = Event.findElement(e,"tr");
var link = $$("a",el)[0]; var link = $$("a",el)[0];