Hi people,
I wonder if someone can give me some pointers here. I have a project which uses the 'Subsites' module. The challenge for me is that there is a possiblity of duplicate content required in one of the sections for one of the subsites and what I am trying to achieve is a dropdown in the cms which allows users to select which subsite the page they are editing belongs to. So in short they can duplicate a page and its children and then select from the dropdown another subsite for that dupicate to sit in. Simple?
... well almost, I've come quite far but I'm a little bit stumped on how I can use the data from the updateCMSFields to populate the SQL Update. For now in the code I have marked it 'somethingneededhere' in the sql for people to see. I want the value from the DropdownField to appear here...
<?php
class SubsiteSelector extends DataObjectDecorator {
function getMyObjectOptions(){
if($Subsite = DataObject::get("Subsite")){
return $Subsite->map("ID", "Title", "Please select");
} else {
return array("No objects found");
}
}
//CMS fields
function updateCMSFields(FieldSet &$fields) {
$fields->addFieldToTab("Root.Behaviour",
new DropdownField(
'Subsites',
'Change subsite this page belongs to',
$this->getMyObjectOptions(),
Session::get('SubsiteID')
));
}
// update which subsite page belongs to
function onAfterWrite(){
parent::onAfterWrite();
DB::query('UPDATE `sitetree` SET `SubsiteID` = "somethingneededhere" WHERE `ID` = '.$this->owner->ID.'');
}
}
Can anyone enlighten me on this please?
Regards