0

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 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.