Hi,
I have build a ProductPage which can have many ReferencePages (many_many and belongs_many_many). So far it works.
Now I want to be able to only select ReferencePages that are within the same "section" of the website. (ProductPage and ReferencePages have the same Root)
I tried using TreeMultiselectField with a DropDownMap as DataSource:
// get the IDs of all Pages with this root:
$root = $this->Level(1);
$ids = $root->getDescendantIDList();
// get all ReferencePages that are in that idlist and convert to dropdown map:
$query = '("SiteTree"."ID" = ' . implode(' OR "SiteTree"."ID" = ', $ids) .')';
$items = DataObject::get("ReferencePage", $query)->map('ID', 'Title', '--empty--');
// create field:
$treeField = new TreeMultiselectField("References", "References", $items);
Works: The TreeMultiselectField only shows References that i want it to show. You can select References and it actually saves the selection to the DB.
Problem: The selected References are not selected /checked in the TreeMultiselectField when the control loads.
Can I select them manually somehow? By setting $treeField->value or something?
Or is there an other way to do all this?
Thanks
Johannes