Default user image in user account menu! I am trying to add a default image to render in the user account menu when the user does not have an image.

CODE:

function nestle_preprocess_menu(&amp;$variables) {
  if($variables['menu_name'] == "account") {
    $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id());
    $name = $variables['user']-&gt;getUsername();
    $picture = file_create_url($file-&gt;getFileUri());
    $picture = $user-&gt;user_picture-&gt;view('large');
    $variables['items']['user.page']['title'] = $name;
    $variables['items']['user.page']['picture'] = $picture;
  }
}


What I did so far, is that I changed the "account" menu link to name of the logged in user and I added the picture of the user in the variables array so that I can render it using twig, The problem is I want to check when the $picture variable is empty ( ie: user has no photo ) it should render a default image from a URL.

PS: I am using Drupal 8, and this code is in the .theme file
You can check if a user picture exists this way:

if (!$user-&gt;user_picture-&gt;isEmpty()) {
  $picture = file_create_url($file-&gt;getFileUri());
  $picture = $user-&gt;user_picture-&gt;view('large');
} else {
  $picture_field = \Drupal\field\Entity\FieldConfig::loadByName('user', 'user', 'user_picture');
  $default_image = $picture_field-&gt;getSetting('default_image');
  $file = \Drupal::entityManager()-&gt;loadEntityByUuid('file', $default_image['uuid']);
  $picture = $file-&gt;getFileUri();
}