Custom module block programmatically assigning it to a specific role I have a Custom module that implements a block how do I programmatically assign it to a specific role or roles in drupal 8?
This is how I did it.

function _&lt;module-name&gt;_check_user_access() {
  $roles = [
    'editor',
    'admin',
  ];


  $current_role = \Drupal::currentUser()-&gt;getRoles();
  foreach($roles as $role) {
    if($role == $current_role[1]) {
      return TRUE;
    }
  }

  return FALSE;
}


See my blog post for more information about it