You are here

public function UserManager::setProfilePicture in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_extra/src/UserManager.php \Drupal\social_auth_extra\UserManager::setProfilePicture()
  2. 8 modules/custom/social_auth_extra/src/UserManager.php \Drupal\social_auth_extra\UserManager::setProfilePicture()
  3. 8.2 modules/custom/social_auth_extra/src/UserManager.php \Drupal\social_auth_extra\UserManager::setProfilePicture()
  4. 8.3 modules/custom/social_auth_extra/src/UserManager.php \Drupal\social_auth_extra\UserManager::setProfilePicture()
  5. 8.5 modules/custom/social_auth_extra/src/UserManager.php \Drupal\social_auth_extra\UserManager::setProfilePicture()
  6. 8.6 modules/custom/social_auth_extra/src/UserManager.php \Drupal\social_auth_extra\UserManager::setProfilePicture()
  7. 8.7 modules/custom/social_auth_extra/src/UserManager.php \Drupal\social_auth_extra\UserManager::setProfilePicture()
  8. 8.8 modules/custom/social_auth_extra/src/UserManager.php \Drupal\social_auth_extra\UserManager::setProfilePicture()

Download and set the picture to profile.

Parameters

string $url: Absolute URL of a picture.

string $account_id: Identifier of account on social network.

Return value

bool Returns TRUE if the picture was saved successfully, FALSE if it didn't.

Overrides UserManagerInterface::setProfilePicture

File

modules/custom/social_auth_extra/src/UserManager.php, line 112

Class

UserManager
Class UserManager.

Namespace

Drupal\social_auth_extra

Code

public function setProfilePicture($url, $account_id) {
  if ($this->profile && ($file = $this
    ->downloadProfilePicture($url, $account_id))) {
    !$this->account ?: $file
      ->setOwner($this->account);
    $file
      ->save();
    $field_name = $this->fieldPicture
      ->getName();
    $this->profile
      ->get($field_name)
      ->setValue($file
      ->id());
    return TRUE;
  }
  return FALSE;
}