public function FloodUnblockAdminForm::buildForm in Flood Unblock 8
Same name and namespace in other branches
- 8.2 src/Form/FloodUnblockAdminForm.php \Drupal\flood_unblock\Form\FloodUnblockAdminForm::buildForm()
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/ FloodUnblockAdminForm.php, line 53
Class
- FloodUnblockAdminForm
- Admin form of Flood unblock.
Namespace
Drupal\flood_unblock\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Get ip entries from flood table.
$flood_ip_entries = $this->floodUnblockManager
->get_blocked_ip_entries();
// Get user entries from flood table.
$flood_user_entries = $this->floodUnblockManager
->get_blocked_user_entries();
$entries = $flood_ip_entries + $flood_user_entries;
$blocks = [];
foreach ($entries as $identifier => $entry) {
$blocks[$identifier] = [
'identifier' => $identifier,
'type' => $entry['type'],
'count' => $entry['count'],
];
if ($entry['type'] == 'ip') {
$blocks[$identifier]['ip'] = $entry['ip'] . $entry['location'];
$blocks[$identifier]['uid'] = '';
$blocks[$identifier]['blocked'] = $entry['blocked'] ? $this
->t('Yes') : "";
}
if ($entry['type'] == 'user') {
$blocks[$identifier]['ip'] = $entry['ip'] . $entry['location'];
$blocks[$identifier]['uid'] = $entry['username'];
$blocks[$identifier]['blocked'] = $entry['blocked'] ? $this
->t('Yes') : "";
}
}
$header = [
'blocked' => $this
->t('Blocked'),
'type' => $this
->t('Type of block'),
'count' => $this
->t('Count'),
'uid' => $this
->t('Account name'),
'ip' => $this
->t('IP Address'),
];
$options = [];
foreach ($blocks as $block) {
$options[$block['identifier']] = [
'blocked' => $block['blocked'],
'type' => $block['type'],
'count' => $block['count'],
'uid' => $block['uid'],
'ip' => $block['ip'],
];
}
$form['top_markup'] = [
'#markup' => $this
->t('<p>Use the table below to view the available flood entries. You can clear seperate items.</p>'),
];
$form['table'] = [
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => $this
->t('There are no failed logins at this time.'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Clear flood'),
];
if (count($entries) == 0) {
$form['submit']['#disabled'] = TRUE;
}
return $form;
}