Previously, when writing a simple settings form, it was common to use system_settings_form()
to quickly save values into the "variables" table. Since all variables are deprecated in Backdrop and should not be used, system_settings_form()
is deprecated as well. Now when creating settings forms, submit handlers must be individually written to save values into the respective configuration file.
Old:
function my_settings_form($form, $form_state) {
$form['my_setting'] = array(
'#type' => 'textfield',
'#title' => t('My setting'),
'#default_value' => variable_get('my_setting', ''),
);
return system_settings_form($form);
}
New:
function my_settings_form($form, $form_state) {
$config = config('my_module.settings');
$form['my_setting'] = array(
'#type' => 'textfield',
'#title' => t('My setting'),
'#default_value' => $config->get('my_setting'),
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
function my_settings_form_submit($form, &$form_state) {
$config = config('my_module.settings');
$config->set('my_setting', $form_state['values']['my_setting']);
$config->save();
backdrop_set_message(t('The configuration options have been saved.'));
}
For now, system_settings_form() has been moved to drupal.inc for sites with compatibility with Drupal still turned on.
Introduced in branch:
1.0.x
Introduced in version:
1.0.0
Impacts:
Module developers
Theme developers
Related Github Issues:
https://github.com/backdrop/backdrop-issues/issues/397