How to display default image in Drupal 8 I have an image field that has a default image if no image is uploaded. In mytheme.theme file I am trying to get the default image and display it. Here is the code that I am using:

$field = $entity-&gt;get($fieldName); // Loading from field definition
if ($field) {
  $default_image = $field-&gt;getSetting('default_image');
  if ($default_image &amp;&amp; $default_image['uuid']) {
    $entityrepository = Drupal::service('entity.repository');
    $defaultImageFile = $entityrepository-&gt;loadEntityByUuid('file', $default_image['uuid']);
    if ($defaultImageFile) {
      $image_uri = $defaultImageFile-&gt;getFileUri();
    }
  }
}


The issue is that the $default_image['uuid'] is empty. I am not sure how that can be if the default image is set. Since the image uuid is empty, the image cannot be loaded and now I am stuck. 

What is wrong with the code that I am using? Or is there another way to accomplish this that works?
Instead of doing this in code, the Drupal core image fields provide a default image setting in the UI as well. 

If you navigate to an image field in the UI (Structure > Content types > [Add/Edit a content type] > Manage fields > [Add/Edit image field]), you can upload a default picture that will be used by Drupal in case no image was provided.