I needed to change image style on the user page, and I also needed to theme some fields. I was able to do everything I needed in the .theme file and the user twig template file.I created a new style ‘user_image’ then in the YOURTHEME.theme file I created a new image url for the image in the hook_preprocess_user.
function YOURTHEME_preprocess_user(&$vars) {
$user = $vars['user'];
// get user image
if (!empty($user->user_picture[0])) {
$cover_image = $user->user_picture[0]->entity->getFileUri();
$image_url = ImageStyle::load('user_image')->buildUrl($cover_image);
$vars['user_pic'] = $image_url;
// get user name
$vars['user_name'] = $user->getUsername();
}
Then in s the user.html.twig I had the two extra variables I could play with.
<div class="row">
<div class="col-sm-8">
{% if content %}
<div class="card">
<div class="row">
<div class="col-sm-3 pull-left">
{% if user_pic %}
<img style="min-width: 100%;" class="img-circle img-thumbnail" src="{{ user_pic }}">
{# {{ content.user_picture }} #}
{% endif %}
</div>
<div class="col-sm-9">
<h1>{{user_name}}</h1>
{# other fields here #}
</div>
</div>
</div>
{% endif %}
</div>
<div class="col-sm-4">
</div>
</div>
Cheers!
How do I get the user profile link to wrap the user image around an anchor?