public function BanAdmin::buildForm

Parameters

string $default_ip: (optional) IP address to be passed on to drupal_get_form() for use as the default value of the IP address form field.

Overrides FormInterface::buildForm

File

drupal/core/modules/ban/lib/Drupal/ban/Form/BanAdmin.php, line 65
Contains \Drupal\ban\Form\BanAdmin.

Class

BanAdmin
Displays banned IP addresses.

Namespace

Drupal\ban\Form

Code

public function buildForm(array $form, array &$form_state, Request $request = NULL, $default_ip = '') {
  $this->request = $request;
  $rows = array();
  $header = array(
    t('banned IP addresses'),
    t('Operations'),
  );
  $result = $this->ipManager
    ->findAll();
  foreach ($result as $ip) {
    $row = array();
    $row[] = $ip->ip;
    $links = array();
    $links['delete'] = array(
      'title' => t('delete'),
      'href' => "admin/config/people/ban/delete/{$ip->iid}",
    );
    $row[] = array(
      'data' => array(
        '#type' => 'operations',
        '#links' => $links,
      ),
    );
    $rows[] = $row;
  }
  $form['ip'] = array(
    '#title' => t('IP address'),
    '#type' => 'textfield',
    '#size' => 48,
    '#maxlength' => 40,
    '#default_value' => $default_ip,
    '#description' => t('Enter a valid IP address.'),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add'),
  );
  $form['ban_ip_banning_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No blocked IP addresses available.'),
    '#weight' => 120,
  );
  return $form;
}