In Drupal 8, I'm getting an exception 'InvalidArgumentException' with message 'The form argument system_theme_settings is not a valid form.'

The story is: I can't add custom colors to my installation profile because of the color module not setting the configuration until a form submit on the theme's settings is called, so I got the form_id with hook_form_alter(), added a custom form_submit handler and serialized the form_state variable into a file (because form_state was gigantic and I had no idea how to find the useful values in there) and loaded it with unserialize() in my installation profile. (Kind of reminiscent of this issue: https://www.drupal.org/node/1963922)

Then, I ran: \Drupal::formBuilder()->submitForm('system_theme_settings', $form_state_variable);

And was told by Drupal that 'system_theme_settings' isn't a valid form. But, how can this be true, if I already added a custom form submit handler to this form using this very form_id?

If I'm not supposed to use a form_id, but rather a specific function or something like that, where should I look to find this function?

1 Answer 1


The api documentation for FormBuilder::submitForm is not exactly correct. The $form_arg argument no longer can be a function, but it refers to the class name or form object of the form. In this case ThemeSettingsForm is the class corresponding to system_theme_settings per its getFormId() method return value.

However I am not sure that calling FormBuilder::submitForm will work from your question because form state may not be valid for the system theme settings form. It may be better to track down what specifically color module is requiring in order to set/save the necessary configuration instead of trying to mock form submission.

  • 1
    Thanks for your comment! I took your advice and looked into the color module and found that it uses color_scheme_form_submit($form, FormStateInterface $form_state). I looked inside it and it seems it doesn't use $form, so I just passed a dummy var, and I passed my unserialize()'d form_state into it and did drush cr and it worked! Commented Oct 29, 2015 at 16:05
  • This can also be done without messing with form state values thus, drush eval '$form_state = new \Drupal\Core\Form\FormState(); \Drupal::formBuilder()->submitForm("\Drupal\system\Form\ThemeSettingsForm", $form_state, "THEME_NAME");'
    – htoip
    Commented Jan 7, 2020 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.