Our site has an object called "TrailNotice" which has a many_many relationship with the page type "TrailSection".
class TrailNotice extends DataObject {
private static $many_many = array(
'TrailSections' => 'TrailSection'
);
This allows a single TrailNotice to be applied across multiple TrailSections via checkboxes in the CMS:
$fields->addFieldToTab('Root.Main', new CheckboxSetField('TrailSections', 'Applies to which trail sections?', DataObject::get('TrailSection')->map('ID', 'Title')));
How do I display the TrailNotices attached to a TrailSection in the TrailSection page controller?
I started with the following code:
class TrailSection_Controller extends Page_Controller {
public function TrailNotices(){
$TrailNotices = DataObject::get('TrailNotice');
return $TrailNotices;
}
But this will get all TrailNotice objects. How do I filter them so only TrailNotices attached to the TrailSection are displayed?