public function FloodSettings::buildForm in Flood settings 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ FloodSettings.php, line 73
Class
- FloodSettings
- Class FloodSettings.
Namespace
Drupal\flood_settings\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config(self::SETTINGS_KEY);
$occurrenceLimits = [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
20,
30,
40,
50,
75,
100,
125,
150,
200,
250,
500,
];
$durationLimits = [
60,
180,
300,
600,
900,
1800,
2700,
3600,
10800,
21600,
32400,
43200,
86400,
];
$durationLimits_options = $this
->buildOptions($durationLimits);
$durationLimits_options[0] = $this
->t('None (disabled)');
ksort($durationLimits_options);
$form['login'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Login'),
];
$form['login']['uid_only'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Username only'),
'#default_value' => $config
->get('uid_only') ?? FALSE,
'#description' => $this
->t('Register flood events based on the uid only, so they apply for any
IP address. This is the most secure option.'),
];
$form['login']['ip_limit'] = [
'#type' => 'select',
'#title' => $this
->t('Failed login (IP) limit'),
'#default_value' => $config
->get('ip_limit') ?? self::DEFAULT_IP_LIMIT,
'#options' => array_combine($occurrenceLimits, $occurrenceLimits),
];
$form['login']['ip_window'] = [
'#type' => 'select',
'#title' => $this
->t('Failed login (IP) window'),
'#default_value' => $config
->get('ip_window') ?? self::DEFAULT_IP_WINDOW,
'#options' => $durationLimits_options,
];
$form['login']['user_limit'] = [
'#type' => 'select',
'#title' => $this
->t('Failed login (username) limit'),
'#default_value' => $config
->get('user_limit') ?? self::DEFAULT_USER_LIMIT,
'#options' => array_combine($occurrenceLimits, $occurrenceLimits),
];
$form['login']['user_window'] = [
'#type' => 'select',
'#title' => $this
->t('Failed login (username) window'),
'#default_value' => $config
->get('user_window') ?? self::DEFAULT_USER_WINDOW,
'#options' => $durationLimits_options,
];
return parent::buildForm($form, $form_state);
}