You are here

public function HostMultipleUnbanConfirm::submitForm in http:BL 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/HostMultipleUnbanConfirm.php, line 205

Class

HostMultipleUnbanConfirm
Provides a multiple host un-ban blacklisted confirmation form.

Namespace

Drupal\httpbl\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('confirm') && !empty($this->hostInfo)) {
    $unban_hosts = [];

    /** @var \Drupal\httpbl\HostInterface[] $hosts */
    $hosts = $this->storage
      ->loadMultiple(array_keys($this->hostInfo));
    foreach ($this->hostInfo as $id => $host_ips) {
      foreach ($host_ips as $host_ip) {
        $host = $hosts[$id];
        if ($this->banManager
          ->isBanned($host_ip)) {

          // Queue the un-banning of any banned host found;
          $unban_hosts[$id] = $host;
        }
      }
    }
    if ($unban_hosts) {
      foreach ($unban_hosts as $unban_host) {
        $this->banManager
          ->unbanIp($unban_host
          ->getHostIp());
      }
      $this->logTrapper
        ->trapNotice('Un-banned @count hosts.', array(
        '@count' => count($unban_hosts),
      ));
      $unbanned_count = count($unban_hosts);
      drupal_set_message($this
        ->formatPlural($unbanned_count, 'Un-banned 1 host.', 'Un-banned @count hosts.'));
    }
    else {

      // Let user know if there was nothing to do.
      drupal_set_message('No hosts were found banned.  There was nothing to do.', 'warning');
    }
    $this->tempStoreFactory
      ->get('host_multiple_unban_blacklisted_confirm')
      ->delete(\Drupal::currentUser()
      ->id());
  }
  $form_state
    ->setRedirect('entity.host.collection');
}