I have a Custom module that implements a block how do I programmatically assign it to a specific role or roles in drupal 8?
1 Answer
This is how I did it.
function _<module-name>_check_user_access() {
$roles = [
'editor',
'admin',
];
$current_role = \Drupal::currentUser()->getRoles();
foreach($roles as $role) {
if($role == $current_role[1]) {
return TRUE;
}
}
return FALSE;
}
See my blog post for more information about it