public function UserStatisticsManager::getUserRole in Opigno statistics 3.x
Get the user role name.
Parameters
\Drupal\user\UserInterface|\Drupal\Core\Session\AccountInterface|null $user: The user to get the role of.
Return value
\Drupal\Core\StringTranslation\TranslatableMarkup The translatable user role name.
File
- src/Services/ UserStatisticsManager.php, line 549 
Class
- UserStatisticsManager
- User statistics manager service definition.
Namespace
Drupal\opigno_statistics\ServicesCode
public function getUserRole(?AccountInterface $user = NULL) : TranslatableMarkup {
  // Add user role.
  if (!$user) {
    $user = $this->account;
  }
  $roles = $user
    ->getRoles(TRUE);
  if (!$roles) {
    $role = $this
      ->t('Student');
  }
  elseif (in_array('administrator', $roles)) {
    $role = $this
      ->t('Administrator');
  }
  else {
    $role = $this
      ->t('Manager');
  }
  return $role;
}