You are here

protected function OAuth2Storage::getUserPicture in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x src/OAuth2Storage.php \Drupal\oauth2_server\OAuth2Storage::getUserPicture()

Get the user's picture to return as an OpenID Connect claim.

Parameters

\Drupal\user\UserInterface $account: The user account object.

Return value

string|null An absolute URL to the user picture, or NULL if none is found.

Throws

\Drupal\Core\Entity\EntityMalformedException

1 call to OAuth2Storage::getUserPicture()
OAuth2Storage::getUserClaims in src/OAuth2Storage.php
Get user claims.

File

src/OAuth2Storage.php, line 998

Class

OAuth2Storage
Provides Drupal OAuth2 storage for the library.

Namespace

Drupal\oauth2_server

Code

protected function getUserPicture(UserInterface $account) {
  if (!user_picture_enabled()) {
    return NULL;
  }
  if ($account->user_picture && $account->user_picture->target_id) {
    $file = File::load($account->user_picture->target_id);
    if ($file) {
      return $file
        ->toUrl('canonical', [
        'absolute' => TRUE,
      ]);
    }
  }
  return NULL;
}