You are here

public function SimpleFbConnectUserManager::setProfilePic in Simple FB Connect 8.3

Same name and namespace in other branches
  1. 8.2 src/SimpleFbConnectUserManager.php \Drupal\simple_fb_connect\SimpleFbConnectUserManager::setProfilePic()

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 $fbid: User's Facebook ID.

Return value

bool True if picture was successfully set. False otherwise.

Deprecated

This method is deprecated as of 8.x-3.1 when the logic of this method was moved to method createUser because the user creation failed when user_picture was required field.

File

src/SimpleFbConnectUserManager.php, line 438

Class

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

Namespace

Drupal\simple_fb_connect

Code

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

  // Try to download the profile picture and add it to user fields.
  if ($this
    ->userPictureEnabled()) {
    if ($file = $this
      ->downloadProfilePic($picture_url, $fbid)) {

      // Set the owner of the file to be the Drupal user.
      $file
        ->setOwner($drupal_user);
      $file
        ->save();

      // Set user's profile picture and save user.
      $drupal_user
        ->set('user_picture', $file
        ->id());
      $drupal_user
        ->save();
      return TRUE;
    }
  }
  return FALSE;
}