Set permanent status for managed_file in theme settings I'm creating some Drupal 8 theme and I need some additional settings for it. So, I have to add some managed_file field in theme settings.

I have theme-settings.php file where I define this field and I want to make this file permanent.

There is what I have in theme-settings.php so far:

&lt;?php

/**
 * @file
 * Provides an additional config form for theme settings.
 */

use Drupal\Core\Form\FormStateInterface;

// Set theme name to use in the key values.
$theme_name = \Drupal::theme()-&gt;getActiveTheme()-&gt;getName();

/**
 * Implements hook_form_system_theme_settings_alter().
 *
 * Form override for theme settings.
 */
function onion_form_system_theme_settings_alter(array &amp;$form, FormStateInterface $form_state) {
  $form['options_settings'] = [
    '#type' =&gt; 'fieldset',
    '#title' =&gt; t('Theme Specific Settings'),
  ];

  // Main navigation logo
  $form['options_settings']['menu_logo'] = [
    '#title' =&gt; t('Menu Logo'),
    '#type' =&gt; 'managed_file',
    '#default_value' =&gt; theme_get_setting('menu_logo'),
    '#upload_location' =&gt; 'public://',
    '#description' =&gt; t('Logo below main navigation. Available extensions (.gif .png .jpg .jpeg)'),
    '#upload_validators' =&gt; array(
      'file_validate_extensions' =&gt; array('gif png jpg jpeg')
    ),
  ];

  $form['#submit'][] = '_onion_form_system_theme_settings_submit';
}

function _onion_form_system_theme_settings_submit(&amp;$form, \Drupal\Core\Form\FormStateInterface &amp;$form_state, $form_id = NULL) {
  $menu_logo_id = $form_state['values']['options_settings']['menu_logo'];
  $menu_logo_file = \Drupal\file\Entity\File::load($menu_logo_id);

  // set status to permanent so that its not deleted
  $menu_logo_file-&gt;setPermanent();
  $menu_logo_file-&gt;save();
}


But I'm getting this warning:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_onion_form_system_theme_settings_submit' not found or invalid function name in Drupal\Core\Form\FormSubmitter-&gt;executeSubmitHandlers() (line 111 of core/lib/Drupal/Core/Form/FormSubmitter.php). 


What I'm doing wrong there and what is the best and right way to set file permanent?
I think you just need to adjust your submission handler; don't include the fieldset "options_settings". I use the getValue() method and pass it an array of values, the form key and the index of its value.

  if ($file_id = $form_state-&gt;getValue(['header_background', '0'])) {
    $file = \Drupal::entityTypeManager()-&gt;getStorage('file')-&gt;load($file_id);
    $file-&gt;setPermanent();
    $file-&gt;save();
  }