logo

User command drupal 8

16 Dec 2021

Programmatically get user picture/image in Drupal 8 or 9

Published On: Thu, 12/16/2021 - 07:53

Following code can be used to get user picture or image by loading user data in Drupal 8

$user = \Drupal\user\Entity\User::load($uid);
$imgpath = $user->get('user_picture')->entity->uri->value;
if(!empty($imgpath)){
	$user_pic = file_create_url($picurl);
}

22 Apr 2020

User related methods in DRUPAL 8

Published On: Wed, 04/22/2020 - 22:13

Get user role of current loggedin user

$user_roles = \Drupal::currentUser()->getRoles();

will return an array like:

Array
(
  [0] => authenticated
  [1] => administrator
  [2] => some_other_role
)

Get user detail of curent loggedin user

$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
user_delete(…