2

How do I make a view block with picture of the currently logged-in user? I am using Drupal 8.

2
  1. Create a new view /admin/structure/views.

enter image description here

  1. Add a contextual filter in view: User: User ID and configure.

enter image description here

  1. Add picture field.

  2. Save.

  3. Show block where you need.

1

If you use the 'Picture' field of user, create your view like this.

  1. Goto /admin/structure/views/add
  2. View settings
    • Show -> Users
  3. Block settings
    • Create a block
  4. Save and Edit

  5. Add field 'Picture'

  6. Click on 'ADVANCED' and add 'Contextual filters'

    • Add 'User ID' -> Provide default value -> Use ID from logged in user -> Apply
  7. Save and add your bloc to the page.

You can also do it programmatically like : http://www.drupal8.ovh/en/tutoriels/107/create-a-simple-block-programmatically Then use following codes to get the image.

$userCurrent = \Drupal::currentUser(); 
$user = \Drupal\user\Entity\User::load($userCurrent->id()); 
$output[] = $user->get('user_picture')->first()->view(); 
return $output;

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