Thursday, 12 July 2018

Get the current logged in user detail.

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.

No comments:

Post a Comment

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...