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) (from r96775)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102407 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-12 03:27:03 +00:00
parent 9e9ec33dd3
commit c077c77c25
3 changed files with 17 additions and 13 deletions

View File

@ -354,7 +354,7 @@ JS;
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() {
if($this->form && $record = $this->form->getRecord()) {
return $record;
} else {
if($this->sourceID()) {
$parentClass = DataObject::get_by_id($this->getParentClass(), $this->sourceID());
} else {
$parentClass = singleton($this->getParentClass());
$parentID = (int)$this->sourceID();
$parentClass = $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')
);
$editLink = Controller::join_links($this->Link(), 'item/' . $childData->ID . '/edit');
$message = sprintf(
_t('ComplexTableField.SUCCESSADD', 'Added %s %s %s'),
$childData->singular_name(),
'<a href="' . $this->Link() . '/item/' . $childData->ID . '/edit">' . $childData->Title . '</a>',
'<a href="' . $editLink . '">' . $childData->Title . '</a>',
$closeLink
);
@ -1007,15 +1011,15 @@ class ComplexTableField_Item extends TableListField_Item {
}
function EditLink() {
return $this->Link() . "/edit";
return Controller::join_links($this->Link(), "edit");
}
function ShowLink() {
return $this->Link() . "/show";
return Controller::join_links($this->Link(), "show");
}
function DeleteLink() {
return $this->Link() . "/delete";
return Controller::join_links($this->Link(), "delete");
}
/**

View File

@ -1128,7 +1128,7 @@ JS
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'];
$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);
@ -1421,7 +1421,7 @@ class TableListField_ItemRequest extends RequestHandler {
);
function Link() {
return $this->ctf->Link() . '/item/' . $this->itemID;
return Controller::join_links($this->ctf->Link(), 'item/' . $this->itemID);
}
function __construct($ctf, $itemID) {

View File

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