21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 208 Views |
-
Passing a value from cmsfield to function?

8 August 2012 at 2:36am
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
-
Re: Passing a value from cmsfield to function?

9 August 2012 at 7:19am
Apologies for being one of those "bump" dudes but I'm going nuts on this one. Does anybody out there have any advice on how to overcome this problem?
Regards
-
Re: Passing a value from cmsfield to function?

9 August 2012 at 3:26pm
Why not just name the DropdownField SubsiteID, so that the ORM handles it for you?
-
Re: Passing a value from cmsfield to function?

9 August 2012 at 11:47pm
Thanks Simon,
I think I've been looking at code for too long and gone mental, why didn't I see this, it was obvious! Thank you, got it working fine now!
... Well almost! All except a page's children. Ideally it would be nice to be able to update the children at the same time. Is there a built in way to cascade changes to children too or would my original idea be needed where an sql query is requried to update any records where ParentID = ID?
Regards
| 208 Views | ||
|
Page:
1
|
Go to Top |

