You are here

public function BanAdmin::buildForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 59
Contains \Drupal\ban\Form\BanAdmin.

Class

BanAdmin
Displays banned IP addresses.

Namespace

Drupal\ban\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $default_ip = '') {
  $rows = array();
  $header = array(
    $this
      ->t('banned IP addresses'),
    $this
      ->t('Operations'),
  );
  $result = $this->ipManager
    ->findAll();
  foreach ($result as $ip) {
    $row = array();
    $row[] = $ip->ip;
    $links = array();
    $links['delete'] = array(
      'title' => $this
        ->t('Delete'),
      'url' => Url::fromRoute('ban.delete', [
        'ban_id' => $ip->iid,
      ]),
    );
    $row[] = array(
      'data' => array(
        '#type' => 'operations',
        '#links' => $links,
      ),
    );
    $rows[] = $row;
  }
  $form['ip'] = array(
    '#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'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Add'),
  );
  $form['ban_ip_banning_table'] = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No blocked IP addresses available.'),
    '#weight' => 120,
  );
  return $form;
}