You are here

public function UserManager::downloadProfilePicture in Open Social 8

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

Saves the picture from URL.

Parameters

string $url: Absolute URL of a picture.

string $account_id: Identifier of account on social network.

Return value

bool|object Object of created file or FALSE when error has occurred.

Overrides UserManagerInterface::downloadProfilePicture

1 call to UserManager::downloadProfilePicture()
UserManager::setProfilePicture in modules/custom/social_auth_extra/src/UserManager.php
Download and set the picture to profile.

File

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

Class

UserManager
Class UserManager.

Namespace

Drupal\social_auth_extra

Code

public function downloadProfilePicture($url, $account_id) {
  $key = $this
    ->getSocialNetworkKey();
  if (!$url || !$account_id) {
    return FALSE;
  }
  if (!($directory = $this
    ->getPictureDirectory())) {
    return FALSE;
  }
  if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
    $this->loggerFactory
      ->get('social_auth_' . $key)
      ->error('The image could not be saved, the directory @directory is not valid.', [
      '@directory' => $directory,
    ]);
    return FALSE;
  }
  $filename = $this->transliteration
    ->transliterate($key . '_' . $account_id . '.jpg', 'en', '_', 50);
  $destination = "{$directory}/{$filename}";
  if (!($file = system_retrieve_file($url, $destination, TRUE, FILE_EXISTS_REPLACE))) {
    $this->loggerFactory
      ->get('social_auth_' . $key)
      ->error('The file @filename could not downloaded.', [
      '@filename' => $filename,
    ]);
    return FALSE;
  }
  return $file;
}