How do I make a view block with picture of the currently logged-in user? I am using Drupal 8.
If you use the 'Picture' field of user, create your view like this.
- Goto /admin/structure/views/add
- View settings
- Show -> Users
- Block settings
- Create a block
Save and Edit
Add field 'Picture'
Click on 'ADVANCED' and add 'Contextual filters'
- Add 'User ID' -> Provide default value -> Use ID from logged in user -> Apply
- 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;