Drupal Version: 8.5.5
Need to assign permission to existing role during module installation: Am using below code in hook_install:
use Drupal\user\RoleInterface;
use Drupal\user\UserInterface;
function hook_install() {
$permission = 'test permission';
$tester_rid = RoleInterface::TESTER;
if ('tester' == Role::load($tester_rid)) {
$tester_role->grantPermission($permission);
$tester_role->save();
}
}
Above grant permission is not working. I have also tried with
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
'my custom permission',
));
user_role_grant_permissions(RoleInterface::TESTER, array(
'my custom permission',
));
Above hook_install is not working.
Pls help
Entity::load
return an entity, not a string. You can't compare it with a string and expect a useful result