- Issue created by @sabrina.liman
- 🇬🇧United Kingdom sabrina.liman
Issue initially created in Opigno_LMS issue queue but this is more fitting. Patch displays correct role in who's new block
We have Opigno 3.1.0 installed. We notice Users who have already been assigned the role "Student" displays with a role of "Manager" when in the "Who's Online" or "Who's New" view blocks. Tracing this through the user--compact.html.twig
and function aristotle_preprocess_user(&$variables)
, it seems this is due to the the function getUsrRole
in the class Drupal\opigno_statistics\Services\UserStatisticsManager
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;
It seems, since a role is set, the first if statement is skipped nd since administrator is not in the roles, Manager is returned....
Create a new user from the admin screen and assign student role to the new user. You will then see the user has "Manager" role.
Why do we need this check? Can we just use the role that is returned?
Active
3.1
Code
Issue initially created in Opigno_LMS issue queue but this is more fitting. Patch displays correct role in who's new block