Configuration form and submission handler
There are the following errors in that code:


You call parent::submitForm($form, $form_state) inside the foreach() loop, when it should be called once, outside the loop
You keep setting element, which means you are only saving a single value
Your code is still accessing the FormStateInterface object as an array, as it was done in Drupal 7


I cannot comment about the \Drupal::state()-&gt;get('cleanupeditform_formkeys') part, except that I would probably inject the service as dependency, but I would rather use the following code.

public function submitForm(array &amp;$form, FormStateInterface $form_state) {
  foreach ((\Drupal::state()-&gt;get('cleanupeditform_formkeys') ?: []) as $key =&gt; $value ) {
    $this-&gt;config('cleanupeditform.admin_settings')
      -&gt;set(CLEANUPEDITFORM_HIDEPREFIX . $key, $form_state-&gt;getValue(CLEANUPEDITFORM_HIDEPREFIX . $key))
      -&gt;set(CLEANUPEDITFORM_ALLOWPREFIX . $key, $form_state-&gt;getValue(CLEANUPEDITFORM_ALLOWPREFIX . $key))
      -&gt;save();
  }
  parent::submitForm($form, $form_state);
}