Hi there,
I was trying to write a Module for having a Menu with Shortlinks. Therefore my Idea was a class Shortlink, inheriting from DataObject and a ShortlinkPage having many shortlinks.
This is the Code:
class ShortLink extends DataObject{
static $db = array (
'LinkTitle' => 'Text'
);
static $has_one = array (
'ShortLink' => 'Page'
);
function getCMSFields_forPopup(){
$fields = new FieldSet();
$fields->push(new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:")));
$fields->push(new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "Page"));
return $fields;
}
}
class ShortLinkPage extends Page {
static $has_many = array (
'ShortLinks' => 'ShortLink'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$shortLinks = new ComplexTableField(
$this,
_t("ShortLinkPage.SHORTLINKS", "Short Links:"),
'ShortLink',
null,
null
//"ShortLink.ShortLinkPageID = {$this->ID}"
);
$fields->addFieldToTab('Root.Content.Shortlinks', $shortLinks);
return $fields;
}
public function getShortLinks(){
$page = $this;
$Shortlinks = $this->ShortLinks();
print_r($Shortlinks); // this is still not ready, but isn't my problem at the moment
/*while(!$Menublock->ID && $page->ParentID != 0){
$page = $page->Parent();
if(!method_exists($page, 'LinkToMenublock') && $page->ParentID != 0){
$page = $page->Parent();
$Menublock = $page->LinkToMenublock();
}else{
$Menublock = $page->LinkToMenublock();
}
}
//return new DataObjectSet($Menublock->Children());
return $Menublock->Children();*/
}
}
class ShortLinkPage_Controller extends ExtendedPage_Controller {
}
What doesn't work is the TreeDropDownField inside the Popup for creating a new shortlink (in Version 2.3.2 and 2.3.3, didn't tested 2.3.1). Is this a general Problem, that doesn't work or have I been doing something wrong? Elsewhere is the an alternative way, to slect a page for a collection of Links?