How to get the currently logged in user's roles in Drupal 8 ?
For example in D7 we have
$current_user = \Drupal::currentUser(); $roles = $current_user->getRoles();
will return an array like:
Array (  => authenticated  => administrator  => some_other_role )
where the array values are role IDs (equivalent to the machine name of the role in Drupal 7). In OO code, use the appropriate mechanism get the current user from the container, eg
$current_user = $container->get('current_user');