In my theme settings under 'admin/appearance/settings/mytheme' I am trying to add an image field.
I have added the following to mytheme.theme
function mytheme_form_system_theme_settings_alter(&$form, Drupal\Core\Form\FormStateInterface $form_state) {
$form['mytheme_settings']['footer_info']['footer_image'] = array(
'#type' => 'managed_file',
'#title' => 'footer image',
'#name' => 'footer_file',
'#default_value' => theme_get_setting('footer_image', 'mytheme'),
'#upload_location' => 'public://'
);
}
This creates a file field in the theme settings page. When I upload the field is saved in my public files
I am now trying to render that file in to a twig template.
I add the following to mytheme.theme to delacre the variable
function mytheme_preprocess_page(&$variables) {
$variables['footer_image'] = theme_get_setting('footer_image','mytheme');
}
Then add {{ footer_image }}
to a template, however the file does not get rendered.
How do I call the file I have uploaded in to my custom theme template. Thanks
Edit.
After searching more, I have discovered the file gets uploaded but the file is getting deleted.
After finding this link it is suggested I sent the file location which I already have done.