XF 2.0 How to add default permission for an addon

Fethi.dz

Well-known member
Hello,

In the Setep.php file for an addon how to add a defaulf permission that apply on the installation.

I have the following permission postRepliesOthers and I want it to be Yes on the addon installation, How to do that?

Thnaks.
 
Using a default setup file from creating a addon, how would you add this into the setup file?
I cant locate any reference on this.

By reffering to XF\AddOn\AbstractSetup line 93

This is how to applyGlobalPermission:
$this->applyGlobalPermission($applyGroupId, $applyPermissionId, $dependGroupId = null, $dependPermissionId = null)
 
By reffering to XF\AddOn\AbstractSetup line 93

This is how to applyGlobalPermission:
$this->applyGlobalPermission($applyGroupId, $applyPermissionId, $dependGroupId = null, $dependPermissionId = null)
Thanks for the reply!
So this has to go into a php file or setup file?
I am really not following.
 
For example:

2017-12-26_20-04-43.webp

Let’s say, you have a new permission where $applyGroupId = forum, and $applyPermissionId = postThread

So, we add in the setup file the following:

PHP:
public function installStep1()
{
   $this->applyGlobalPermission(forum, postThread, $dependGroupId = null, $dependPermissionId = null);
}

Note: The above install step will apply a YES value as default while installing the Add-on.

Enjoy ;)
 
Last edited:
For example:

View attachment 165089

Let’s say, you have a new permission where $applyGroupId = forum, and $applyPermissionId = postThread

So, we add in the seteup file the following:

PHP:
public function installStep1()
{
   $this->applyGlobalPermission(forum, postThread, $dependGroupId = null, $dependPermissionId = null);
}

Note: The above install step will apply a YES value as default while installing the Add-on.

Enjoy ;)

PHP:
public function installStep1()
{
   $this->applyGlobalPermission('forum', 'postThread');
}

This is the correct code :)

The remainder of the two parameters are used if you want to only grant the permission to user groups who already have another permission.

For instance, if you want to grant customPermissionGroup - customPermissionId permission if someone already has post thread permissions, you'd do $this->applyGlobalPermission('customPermissionGroup', 'customPermissionId', 'forum', 'postThread');


Fillip
 
Thank you both for the help.
I managed to finally figure it out, but have 1 more question about this.
Is it possible to just set the default permission for the admin group and not the rest using this method?
 
Last edited:
Does anyone know if there's a way to do this without a setup file entry? My add-on I'm fixing to release does not need a setup file and I want to set my permissions to default 'yes' when they install it.

Any ideas? @Chris D ? I'm working on a most users ever online add-on and I'm almost done with it. It's a really great add-on and even implements a widget and options for putting the counts under members online. It's got counts for all users, members, and even guests. I'm almost done with it but I don't know how to setup default permissions set to 'yes'.
 
It can only be done in the add-on Setup file.

EDIT: Nevermind, the issue I just posted about was because for some reason the setup file made permissions on the actual user (staff members) and not just the usergroup. Anyways I'd rather not take that route Chris but I appreciate the info.

EDIT: I actually think I may give this a try. Shouldn't be a big deal to setup.

Regards,

Brad
 
Last edited:
@Chris D does this only work when when you build your add-on and install it the normal way? I ran the installStep1() with the code in it, replacing my permission group ID and permission ID and it switched them all to 'yes' but it doesn't work until I click save. Any idea?
 
Back
Top Bottom