I am using the following code for Drupal 6.
foreach (variable_get('cleanupeditform_formkeys', 0) as $key => $value ) {
$form['cleanupedit_hide'][CLEANUPEDITFORM_HIDEPREFIX . $key] = array(
'#type' => 'checkbox',
'#title' => t('Hide ') . $value,
'#default_value' => variable_get(CLEANUPEDITFORM_HIDEPREFIX . $key , 1),
);
}
I need to convert this code to Drupal 8.
In buildForm()
I generate the form. I need to save the checkboxes values, and I am using the following code.
public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ((\Drupal::state()->get('cleanupeditform_formkeys') ?: 0) as $key => $value ) {
parent::submitForm($form,$form_state);
$this->config('cleanupeditform.admin_settings')
->set('element', $form_state['cleanupedit_hide'][CLEANUPEDITFORM_HIDEPREFIX . $key])
->set('element', $form_state['cleanupedit_allow'][CLEANUPEDITFORM_ALLOWPREFIX . $key])
->save();
}
parent::submitForm($form, $form_state);
}
Please help me to find out a solution.