Custom submit handler for theme settings form I am creating a new D8 theme and having slideshow functionality in it. For slideshow, we have title, description and image field in the theme settings form. I am able to alter the theme setting form using THEME_NAME_form_system_theme_settings_alter, but when I add a custom submit handler the form seems to break and get internal server error. 

My objective for adding custom submit is to make the uploaded files status as permanent.

Here is my code,

function THEME_NAME_form_system_theme_settings_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  // $form['#submit'][] = 'custom_settings_form_submit'; //tried this as well
  $form['actions']['submit']['#submit'][] = '_custom_settings_form_submit';
}

function _custom_settings_form_submit(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $account = \Drupal::currentUser();
  $values = $form_state-&gt;getValues();
  for ($i = 0; $i &lt;= SLIDESHOW_COUNT; $i++) {
    if (isset($values['slide_image_path' . $i]) &amp;&amp; !empty($values['slide_image_path' . $i])) {
      // Load the file via file.fid.
      $file = file_load($values['slide_image_path' . $i][0]);
      // Change status to permanent.
      $file-&gt;setPermanent();
      $file-&gt;save();
      // $file_usage = \Drupal::service('file.usage');
      // $file_usage-&gt;add($file, 'user', 'user', $account-&gt;id());
    }
  }
}


NOTE:
This is the error present in apache error log:
PHP Fatal error:  Invalid placeholder (!message) in string: %type: !message in %function (line %line of %file). in /core/lib/Drupal/Component/Render/FormattableMarkup.php on line 240

Does anyone have any idea where I'm doing it wrong? or is there any workaround for making the file status permanent?
From Drupal 8: Use Custom Submit Handler for Theme Settings Form:

Use this method to add custom submit handler for theme settings form in drupal 8.

/**
 * Implements hook_form_system_theme_settings_alter().
 */
function MY_THEME_form_system_theme_settings_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $theme_file = drupal_get_path('theme', 'MY_THEME') . '/MY_THEME.theme';
  $build_info = $form_state-&gt;getBuildInfo();
  if (!in_array($theme_file, $build_info['files'])) {
    $build_info['files'][] = $theme_file;
  }
  $form_state-&gt;setBuildInfo($build_info);

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

function MY_THEME_form_system_theme_settings_submit(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  // TODO: Extra submssio logic.
  // This submit handler will be called before default submit handler for this form.
}