Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

adding new groups via a module

Go to End

3 Posts   1406 Views


Community Member, 49 Posts

13 April 2012 at 4:23am

Hi, im working on a small module (part time hobby) and want it to be so that on install the module will create 3 new member groups, Bronze, Silver, Gold... (they will not have access to admin CMS, just seperate pages at the front end of the site).

The way im hoping to do it is via the modules _config.php file, now i know i can set permissions via GroupDecorator, but how do i make it so that the groups are created on module install and not have to be done via the admin cms >> security tab, i have looked high and low for ideas over the last two days and everything is just returning a blank for me on how i can implement this, does anyone have any ideas on how it can be done.. Thanks


Forum Moderator, 5523 Posts

13 April 2012 at 7:00pm

Well there aren't any hooks like onInstall or anything but what most devs do is hook into requireDefaultRecords() on a dataobject. This function is run on every dev/build.

So on a DataObject subclass in your module define something like

function requireDefaultRecords() {

if(!DataObject::get('Group', "Code = 'bronze'")) {
$group = new Group();
$group->Code = 'bronze';
$group->Title = "Bronze";


Community Member, 49 Posts

19 April 2012 at 3:43am

ahh thanks for this Willr, i did spot the requireDefaultRecords() code in group.php before i posted my question, but wasnt too sure if that was the right way to go about it, you cleared up that it is, tyvm..