Here's a random shot in the dark..
$fields->addFieldToTab("Root.Content.Students", new LiteralField('list', $this->getManyManyComponents('Students')->UL()));
No idea if that will work, but worth a shot!
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
Here's a random shot in the dark..
$fields->addFieldToTab("Root.Content.Students", new LiteralField('list', $this->getManyManyComponents('Students')->UL()));
No idea if that will work, but worth a shot!
Sorry for necroposting, but i had the same need to show only related objects. I have many EventPages and many Members. Each of members can be assigned to each EventPage, but there are about 1,000 users and usually about 200-300 are assigned. So I did the next:
EventPage.php:
class EventPage extends Page
{
.
.
static $many_many = array(
'Members' => 'Member'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$sqlQuery = new SQLQuery();
$sqlQuery->select = array('MemberID');
$sqlQuery->from = array("EventPage_Members");
$sqlQuery->where = array("EventPageID=".$this->ID);
$rawSQL = $sqlQuery->sql();
$result = $sqlQuery->execute();
$query="MemberID=";
foreach($result as $row){
$query .= $row[MemberID]." OR MemberID=";
}
$query .= $row[MemberID];
$modulesTablefield = new ManyManyComplexTableField(
$this,
'Members',
'Member',
array(
'Name' => 'Name',
'Email' => 'Email'
),
'getCMSFields_forPopup',
$query,
'',
''
);
$modulesTablefield->setReadOnly('true');
$fields->addFieldToTab( 'Root.Content.Subscribers', $modulesTablefield );
return $fields;
}
.
.
}
In Member.php from sapphire i also made some changes like
static $belongs_many_many = array(
'Events' => 'EventPage'
);
What is my code doing? It takes all MemberID which are related to the current EventPage from many_many table which in my case named EventPage_Members and had columns MemberID, EventPageID. Then I made a $query with that MemberIDs which is used as filter in ManyManyComplexTableField constructor.
This solves only one half of problem - i couln't remove that markers... Hope others could =)
I'm actually just about to release a bunch of new features for MMDOM, and one of them is a "related objects only" checkbox. I don't know if that will help you or not.