I have two classes:
Many WarePages = many WareItems
and WareItem belongs many WarePages
When I edit WarePage I have to see all WareItems and if i need i have to add them in that dialog.
That one function displays all WareItems and places 'checked' only for items that belongs WarePage object and I can easily check or uncheck items, but I want to use DataObjectManager to display Items more correctly
$itemList = DataObject::get('WareItem');
$fields->addFieldToTab('Root.Content.WareItems', new CheckboxSetField('WareItems', '', $itemList));
But DataObjectManager just displays all WareItems:
class WarePage extends Page {
static $many_many = array(
"WareItems" => "WareItem",
);
function getCMSFields() {
$fields = parent::getCMSFields();
$dataobjectmanager = new FileDataObjectManager(
$this,
'WareItems', // Source name
'WareItem', // Source class
'Photo', // File name on DataObject
array('Name' => 'Name','WareBrand.Name'=>'Brand','Article' => 'Article'),
'getCMSFields_forPopup'
);
$dataobjectmanager->setUploadFolder('WareHouse/'.$this->title);
$dataobjectmanager->enableUploadDebugging();
..
$fields->addFieldToTab("Root.Content.WarePageItems", $dataobjectmanager);
return $fields;
}
}
class WareItem extends DataObject {
...
static $belongs_many_many = array(
'WarePages' => 'WarePage'
);
..
}