Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » adding new groups via a module

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

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

Page: 1
Go to End
Author Topic: 460 Views
  • Mrfixer
    Avatar
    Community Member
    49 Posts

    adding new groups via a module Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: adding new groups via a module Link to this post

    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() {
    parent::requireDefaultRecords();

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

  • Mrfixer
    Avatar
    Community Member
    49 Posts

    Re: adding new groups via a module Link to this post

    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..

    460 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.