Referencing an existing image in theme settings In a custom theme (Drupal 8.4.3) I would like to add a theme setting, where I can reference (not upload) an image to use as a background image. Like in a normal reference field, already uploaded images should be choosable; these images are stored in media entities.
How can I build such a theme setting? I only found information about Uploading images in theme settings.
I haven't been able to find an example of this, either, but here's a simple demo setting a reference to a media/image in theme settings (with the autocomplete widget):

use Drupal\Core\Form\FormStateInterface;

function THEME_form_system_theme_settings_alter(&amp;$form, FormStateInterface &amp;$form_state, $form_id = NULL) {
  // Work-around for a core bug affecting admin themes. See issue #943212.
  if (isset($form_id)) {
    return;
  }

  $opts = [
    '#type'          =&gt; 'entity_autocomplete',
    '#title'         =&gt; t("Call to Action Background"),
    '#description'   =&gt; t("Default call to action background media image; may be overridden on individual elements."),
    '#target_type'   =&gt; 'media',
    '#selection_settings' =&gt; ['target_bundles' =&gt; ['image']],
  ];
  if ($default_id = theme_get_setting('call_to_action_background')) {
    // element stores an int ID, but default value has to be the loaded entity
    $image = \Drupal::entityTypeManager()-&gt;getStorage('media')-&gt;load($default_id);
    $opts['#default_value'] = $image;
  }
  $form['call_to_action_background'] = $opts;

}


To retrieve and render, use a THEME_preprocess hook with parameter &amp;$variables:

$media_id = theme_get_setting('call_to_action_background');
$media = \Drupal::entityTypeManager()-&gt;getStorage('media')-&gt;load($media_id);
$variables['media_build'] = \Drupal::entityTypeManager()-&gt;getViewBuilder('media')-&gt;view(‌​$media, 'some_media_display_mode');


The render array is then available in twig:

{{ media_build }}