BanAdmin::buildForm

public BanAdmin::buildForm(array $form, FormStateInterface $form_state, $default_ip = '')

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 54

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;
}
doc_Drupal
2016-10-29 08:45:23
Comments
Leave a Comment

Please login to continue.