21279 Posts in 5729 Topics by 2600 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 230 Views |
-
adding new groups via a module

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
-
Re: adding new groups via a module

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() {
parent::requireDefaultRecords();if(!DataObject::get('Group', "Code = 'bronze'")) {
$group = new Group();
$group->Code = 'bronze';
$group->Title = "Bronze";
...
$group->write();
}
..
} -
Re: adding new groups via a module

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..
| 230 Views | ||
|
Page:
1
|
Go to Top |


