In Drupal 7, I'm trying to grant a permission to a user role using hook_install and it doesn't work. But it works with hook_enable. Do you know how to make it work with hook_install as well?
function porta_batch_editor_install() {
$permissions = array('access porta batch editor');
//grant 'access porta batch editor' permission to pb role
foreach(array('pb role') as $role_name) {
$role = user_role_load_by_name($role_name);
user_role_grant_permissions($role->rid, $permissions);
}
}
It works with the following approach:
function porta_batch_editor_enable() {
$permissions = array('access porta batch editor');
//grant 'access porta batch editor' permission to pb role
foreach(array('pb role') as $role_name) {
$role = user_role_load_by_name($role_name);
user_role_grant_permissions($role->rid, $permissions);
}
}