Get all titles of a many_many component in a GridField summary

Assuming you have a DataObject with $many_many Tags, you can easily add all Tag's Titles comma seperated to $summary_fields using PHP's join method, even sorted by the SortOrder of the Tag DataObject, given it has $default_sort set properly:

private static $summary_fields = [
    'Title' => 'Title',
    'TagsForSummary' => 'Tags'

public function TagsForSummary() {
    return join(', ', $this->Tags()->Column('Title'));
Rate this post

Post your comment


No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments