We have the syntax of current logged-in user detail, Please have a look.
1. Logged-in user id : $uid = \Drupal::currentUser()->id();
2. Current User Detail Array : $current_user_detail = \Drupal::currentUser();
3. Current Logged-in User Role Array: $current_user_role = \Drupal::currentUser()->getRoles();
If we have multiple roles for single user and we have to check one role is exist or not in roles array.
Syntax..
if(in_array("my_role", $current_user_role )){
\\ my role exist in this array..
}
4. Current User Default Language : $langcode = \Drupal::currentUser()->getPreferredLangcode();
Note: If have any suggestions or issue regarding 'Get the current logged in user detail' then you can ask by comments.
1. Logged-in user id : $uid = \Drupal::currentUser()->id();
2. Current User Detail Array : $current_user_detail = \Drupal::currentUser();
3. Current Logged-in User Role Array: $current_user_role = \Drupal::currentUser()->getRoles();
If we have multiple roles for single user and we have to check one role is exist or not in roles array.
Syntax..
if(in_array("my_role", $current_user_role )){
\\ my role exist in this array..
}
4. Current User Default Language : $langcode = \Drupal::currentUser()->getPreferredLangcode();
Note: If have any suggestions or issue regarding 'Get the current logged in user detail' then you can ask by comments.
No comments:
Post a Comment