I have a many_many relationship that I am trying to set with a CheckboxSetField.
In my getCMSFields function I have:
$fields->addFieldToTab("Root.Vehicle", new CheckboxSetField('Categories', 'CategoryPage', $this->getCategories(), $this->CurrentCategories()));
And the corresponding functions are:
function getCategories(){
if($Pages = DataObject::get('CategoryPage')){
$data = array();
foreach($Pages as $page){
$data[$page->ID] = $page->Title;
}
return $data;
} else {
return array('No Objects found');
}
}
function CurrentCategories(){
$data = array();
$do = CategoryPage::get()->leftJoin('ProductPage_Categories', '"CategoryPage"."ID" = "ProductPage_Categories"."CategoryPageID"')->filter(array("ProductPageID" => $this->ID));
if($do){
foreach($do as $cat){
$data[$cat->ID] = $cat->ID;
}
return $data;
}
}
The categories are saving to the database no problem, but I can't get the checkboxes to display as checked. If I echo out the CurrentCategories function results the correct information is there, just not sure what I am missing to make the boxes show as checked.
Thanks