banIp example


  public function fields() {
    return [
      'ip' => $this->t('The blocked IP address.'),
    ];
  }

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    $this->banManager->banIp($row->getDestinationProperty('ip'));

    return ['ip' => $row->getDestinationProperty('ip')];
  }

}
    // TODO: On some systems this test fails due to a bug/inconsistency in cURL.     // $edit = array();     // $edit['ip'] = \Drupal::request()->getClientIP();     // $this->drupalGet('admin/config/people/ban');     // $this->submitForm($edit, 'Save');     // $this->assertSession()->pageTextContains('You may not ban your own IP address.');
    // Test duplicate ip address are not present in the 'blocked_ips' table.     // when they are entered programmatically.     $banIp = new BanIpManager($connection);
    $ip = '1.0.0.0';
    $banIp->banIp($ip);
    $banIp->banIp($ip);
    $banIp->banIp($ip);
    $query = $connection->select('ban_ip', 'bip');
    $query->fields('bip', ['iid']);
    $query->condition('bip.ip', $ip);
    $ip_count = $query->execute()->fetchAll();
    $this->assertCount(1, $ip_count);
    $ip = '';
    $banIp->banIp($ip);
    $banIp->banIp($ip);
    $query = $connection->select('ban_ip', 'bip');
    

    elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) {
      $form_state->setErrorByName('ip', $this->t('Enter a valid IP address.'));
    }
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $ip = trim($form_state->getValue('ip'));
    $this->ipManager->banIp($ip);
    $this->messenger()->addStatus($this->t('The IP address %ip has been banned.', ['%ip' => $ip]));
    $form_state->setRedirect('ban.admin_page');
  }

}
Home | Imprint | This part of the site doesn't use cookies.