Create a dummy module with a settings form which includes an interval form element.
$form['emails']['expiry_warning_period'] = [
'#type' => 'interval',
'#title' => $this->t('Expiry Warning Period'),
'#description' => $this->t('Set the time before expiration that the warning email is sent.'),
'#default_value' => $config->get('expiry_warning_period') ?? ['interval' => 1, 'period' => 'day'],
];
In the submitForm function, notice that it is necessary to get the values using the keys 'interval' and 'period'.
This makes it impossible to have more than one interval form element in the form.
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('my_module.settings');
// This doesn't work...
// $config->set('expiry_warning_period', $form_state->getValue('expiry_warning_period'));
// But this does...
$config->set('expiry_warning_period', ['interval' => $form_state->getValue('interval'), 'period' => $form_state->getValue('period')]);
$config->save();
parent::submitForm($form, $form_state);
}
Active
1.14
Code