How to get a user's profile picture URL? I need to get the user's profile picture using the following code:

\Drupal::service('renderer')-&gt;renderPlain(\Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id())-&gt;user_picture-&gt;first()-&gt;view('large'))


It returns an object with the image tag, but it fails with the _Call to a member function view() on a non-object_ error when a user has no profile picture set.

I also tried the answer to "How do I get the default user picture?", but it gives the error 


  Drupal\Core\Database\InvalidQueryException: Query condition 'file_managed.uuid IN ()' cannot be empty.
The code is OK, but you have to check if the field is not empty:

if ($user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id())) {
  if (!$user-&gt;user_picture-&gt;isEmpty()) {
    $picture = $user-&gt;user_picture-&gt;view('large')
  }
  else {
    $picture = // get default picture
  }
}


In Drupal 8 don't use render service. The new template system does this automatically.