2

I load a user object, and I would like to be able to show the user's picture somewhere. I tried the following code.

$row_user = \Drupal\user\Entity\User::load($uid)->user_picture->first()->view('large');

What I get is this (using kint()).

the user_picture

This user has a picture and it is shown correctly in the user page.

How do I exactly show the picture associated with a user account?

1

Just like every other render array, render it.

If you print it out in twig, that just works, in PHP, use \Drupal::service('renderer')->render().

  • Thanks. I was wondering why #url => NULL because I would like to get the URL to the image. – Finn Oct 6 '15 at 10:44
  • large is a user view mode, not an image style. You can create and configure the field there to show a link. Or pass an array with configuration to it, same structure as stored in view displays – Berdir Oct 6 '15 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.