I’ve got a quite large website with over 20 roles and permissions. However, it are always the same permissions, but depending on who created the content, the permissions differ…
So what I do now is this:
// Make the new role
$role = new stdClass;
$role->name = 'Redacteur 1';
$role->weight = 3;
user_role_save($role);
// Permissions to assign to the role.
// Note these are defined in hook_permission()
$perms = array(
'access content','access content overview'
);
// Grant the permissions. This function takes care of all necessary cache resets
user_role_grant_permissions($role->rid, $perms);
// Make the new role
$role = new stdClass;
$role->name = 'Redacteur 2';
$role->weight = 3;
user_role_save($role);
// Permissions to assign to the role.
// Note these are defined in hook_permission()
$perms = array(
'access content','access content overview'
);
// Grant the permissions. This function takes care of all necessary cache resets
user_role_grant_permissions($role->rid, $perms);
Isn’t there a way to do this with some kind of array so I don’t end up with a 1000 line of code. When you want to change something in the permissions, you have to revise all the roles… This must be easier to do. Any advice?
I wrote some default function to acomplish this goal: