I'm developing a theme that it requires to have a header image on the front page, so I have this.
casper.theme
function casper_form_system_theme_settings_alter(&$form, &$form_state) {
$form['theme_extra']['front_page_background_image'] = array(
'#type' => 'managed_file',
'#title' => 'Front Page Background Image',
'#description' => 'Add background image for the front page',
'#required' => FALSE,
'#weight' => -4,
'#upload_location' => file_default_scheme() . '://theme/backgrounds/',
'#default_value' => theme_get_setting('front_page_background_image' , 'casper'),
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg'),
),
);
}
However, after it, while the file been missing and after some reading, I find out that is because managed_file does not save your image permanent.
There are similar questions:
Is there a way to add managed_file field to theme-settings.php? is specified to Drupal 7.
Drupal 8 Theme Header Background Image Upload is using "file" type instead of managed_file. I already tried something similar to what the Mayo theme is doing, but I was not able to successfully figure it out.
How can I save my image permanently?