Ability to automatically limit items in a GridField relation

67 views
Skip to first unread message

Patrick Nelson

unread,
Feb 24, 2016, 7:44:23 PM2/24/16
to silverst...@googlegroups.com
In case anyone else finds this useful, I setup a quick module which allows you to centrally setup a hard limit on relations. In my use case, I wanted to set an upper limit on the number of many_many relations which happened to already be managed in a GridField but also was being modified externally (e.g. $obj->MyRelation()->add($item)). 

So, I wanted a SilverStripe'ish method of centrally managing this without getting too verbose. My solution was to incorporate this via a component into the existing GridField and let the rendering of that GridField modify the relation. In my case, I happen to also need to externally "touch" this (and trigger an update/trimming of the relation) by proxy of accessing the ->getCMSFields() method and calling ->getManipulatedList() on that grid (but I do that for other reasons). In my case the reasoning is also to force GridFieldSortableRows to properly update, but I digress.

Here it is if you'd like to give it a look; PR's welcome!

Reply all
Reply to author
Forward
0 new messages