5098 Posts in 1518 Topics by 1115 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 447 Views |
-
[Solved] Limiting TreeMultiSelect

16 April 2011 at 11:42pm
I have a working TreeMultiSelect, the sourceObject I've used is a subtype of page (Gallery).
However the field shows the whole SiteTree, rather than just these subtypes. Thankfully it ignores if you try to pick a normal page but it still bugs me.
Probably unrelated but Photograph is managed in ModelAdmin
class Photograph extends DataObject {
...
static $many_many = array(
'Galleries' => 'Gallery'
);
...function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Galleries", new TreeMultiselectField('Galleries', 'Choose Galleries to show Photo', "Gallery"));
return $fields;
}...
}
class Gallery extends Page {
...
static $belongs_many_many = array(
'Photographs' => 'Photograph'
);}
class Gallery_Controller extends Page_Controller {
...}
-
Re: [Solved] Limiting TreeMultiSelect

16 April 2011 at 11:55pm
Hi Phill,
This is the correct behaviour when passing in a 'hierarchy' object as the 3rd parameter. It needs to display all types in order to generate the tree view.
If you wish to only see your Gallery page types then you can pass an array of key/values pairs as the 3rd param instead. This will mean that you have a flat list to select from as a hierarchy no longer exists. You could do this like so:
function getCMSFields() {
$fields = parent::getCMSFields();
$galleryPages = DataObject::get('Gallery');
$fields->addFieldToTab("Root.Galleries", new TreeMultiselectField('Galleries', 'Choose Galleries to show Photo', $galleryPages->map()));
return $fields;
}
| 447 Views | ||
|
Page:
1
|
Go to Top |


