8 – How to display the status of the user?

you can use template_preprocess_user as


 
 
 
 / **
* Implements hook_preprocess_user ().
* /
function mytheme_preprocess_user (& $ variables) {
// retrieve a user object
$ user = $ variables['elements']['#user'];
$ status = & # 39;
// - Check if the user has logged in
if ($ user-> isAuthenticated ()) {
$ status = & # 39; Online & # 39 ;;
}
other {
// - Get the last hour of access
$ last_access_time = $ user-> getLastLoginTime ();
$ number_minutes = (time () - $ last_access_time) / 60;
if ($ number_minutes> 30) {
$ status = "Absent";
}
$ status = & # 39; offline & # 39 ;;
}
$ variables['status'] = $ status;
}

In your model check on status variable like this:

{% if online ==> Online}
      Online
{% elseif Online == Absentee%
      Absent
{% other%}
      Offline
{% end if %}