public function AutobanDeleteAllForm::buildForm in Automatic IP ban (Autoban) 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 FormInterface::buildForm
File
- src/
Form/ AutobanDeleteAllForm.php, line 63
Class
- AutobanDeleteAllForm
- Class AutobanDeleteAllForm.
Namespace
Drupal\autoban\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = [];
$controller = $this->autoban;
$form['rule_type'] = [
'#type' => 'select',
'#title' => $this
->t('Rule type'),
'#default_value' => 0,
'#options' => $controller
->ruleTypeList(),
];
$form['type'] = [
'#type' => 'textfield',
'#title' => $this
->t('Type'),
'#maxlength' => 255,
];
$form['message'] = [
'#type' => 'textfield',
'#title' => $this
->t('Message pattern'),
'#maxlength' => 255,
];
$form['referer'] = [
'#type' => 'textfield',
'#title' => $this
->t('Referrer pattern'),
'#maxlength' => 255,
];
$thresholds_config = $this
->config('autoban.settings')
->get('autoban_thresholds');
$thresholds = !empty($thresholds_config) ? explode("\n", $thresholds_config) : [
1,
2,
3,
5,
10,
20,
50,
100,
];
$thresholds_options = [
0 => $this
->t('All'),
] + array_combine($thresholds, $thresholds);
$form['threshold'] = [
'#type' => 'select',
'#title' => $this
->t('Threshold'),
'#options' => $thresholds_options,
];
$form['user_type'] = [
'#type' => 'select',
'#title' => $this
->t('User type'),
'#default_value' => 0,
'#options' => $controller
->userTypeList(),
];
$providers = [];
$banManagerList = $controller
->getBanProvidersList();
if (!empty($banManagerList)) {
foreach ($banManagerList as $id => $item) {
$providers[$id] = $item['name'];
}
}
$form['provider'] = [
'#type' => 'select',
'#title' => $this
->t('IP ban provider'),
'#options' => [
0 => $this
->t('All'),
] + $providers,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Delete all'),
];
return $form;
}