public function BanAdmin::buildForm in Drupal 8
Same name and namespace in other branches
- 9 core/modules/ban/src/Form/BanAdmin.php \Drupal\ban\Form\BanAdmin::buildForm()
- 10 core/modules/ban/src/Form/BanAdmin.php \Drupal\ban\Form\BanAdmin::buildForm()
Parameters
string $default_ip: (optional) IP address to be passed on to \Drupal::formBuilder()->getForm() for use as the default value of the IP address form field.
Overrides FormInterface::buildForm
File
- core/
modules/ ban/ src/ Form/ BanAdmin.php, line 56
Class
- BanAdmin
- Displays banned IP addresses.
Namespace
Drupal\ban\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $default_ip = '') {
$rows = [];
$header = [
$this
->t('banned IP addresses'),
$this
->t('Operations'),
];
$result = $this->ipManager
->findAll();
foreach ($result as $ip) {
$row = [];
$row[] = $ip->ip;
$links = [];
$links['delete'] = [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('ban.delete', [
'ban_id' => $ip->iid,
]),
];
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
$rows[] = $row;
}
$form['ip'] = [
'#title' => $this
->t('IP address'),
'#type' => 'textfield',
'#size' => 48,
'#maxlength' => 40,
'#default_value' => $default_ip,
'#description' => $this
->t('Enter a valid IP address.'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Add'),
];
$form['ban_ip_banning_table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this
->t('No blocked IP addresses available.'),
'#weight' => 120,
];
return $form;
}