You are here

public function SocialAuthUserManager::setProfilePic in Social Auth 8

Downloads and sets user profile picture.

Parameters

User $drupal_user: User object to update the profile picture for.

string $picture_url: Absolute URL where the picture will be downloaded from.

string $id: User's ID.

Return value

bool True if picture was successfully set. False otherwise.

1 call to SocialAuthUserManager::setProfilePic()
SocialAuthUserManager::authenticateUser in src/SocialAuthUserManager.php
Creates and/or authenticates an user.

File

src/SocialAuthUserManager.php, line 558

Class

SocialAuthUserManager
Contains all logic that is related to Drupal user management.

Namespace

Drupal\social_auth

Code

public function setProfilePic(User $drupal_user, $picture_url, $id) {

  // Try to download the profile picture and add it to user fields.
  if ($this
    ->userPictureEnabled()) {
    if ($file = $this
      ->downloadProfilePic($picture_url, $id)) {
      $drupal_user
        ->set('user_picture', $file
        ->id());
      $drupal_user
        ->save();
      return TRUE;
    }
  }
  return FALSE;
}