Hi everyone
Just trying to create a simple related pages, which oddly I can not find a tut for anywhere! I will make one once this is finished.
What I want to do is pull through the Related Page details into the summary fields, so I can see whats related instead of just the ID. I have no idea how to do this...
So i have...
<?php
class RelatedPage extends DataObject {
public static $db = array(
"SortOrder" => "Int",
"RelatedPageID" => "Int"
);
public static $has_one = array(
"Page" => "Page"
);
public static $has_many = array(
);
public static $field_labels = array(
);
static $summary_fields = array (
$this->Link;
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main',new TreeDropdownField("RelatedPageID", "Select related page", "SiteTree"));
$fields->removeByName('SortOrder');
$fields->removeByName('PageID');
return $fields;
}
public function Link(){
if ($this->RelatedPageID){
$doSet = DataObject::get_by_id("Page", $this->RelatedPageID);
$parentID = $doSet->ParentID;
$URLString = $doSet->URLSegment;
while ($parentID != 0){
$doSet = DataObject::get_by_id("Page", $parentID);
$parentID = $doSet->ParentID;
$URLString = $doSet ->URLSegment . '/' . $URLString;
}
return Director::BaseURL() . $URLString;
} else {
return false;
}
}
}
On the summary page of "Page" i would like to see
Page Title, Thumbnail (which is and has_one image on Page) and Link (which is the function above).
Any ideas?
Thanks!