You are here

public function AdvbanIpManager::formatIp in Advanced ban 8

Format of the IP record (individual or range).

Parameters

string $ip: Banned IP address.

string $ip_end: Banned IP address (end of range).

Return value

string Format string for IP addresses.

Overrides AdvbanIpManagerInterface::formatIp

File

src/AdvbanIpManager.php, line 252

Class

AdvbanIpManager
Ban IP manager.

Namespace

Drupal\advban

Code

public function formatIp($ip, $ip_end = '') {
  if (!empty($ip_end)) {
    if (is_numeric($ip)) {
      $ip = long2ip($ip);
    }
    if (is_numeric($ip_end)) {
      $ip_end = long2ip($ip_end);
    }
    $format_text = $this->config
      ->get('advban.settings')
      ->get('range_ip_format') ?: '@ip_start ... @ip_end';
    $text = new FormattableMarkup($format_text, [
      '@ip_start' => $ip,
      '@ip_end' => $ip_end,
    ]);
    return $text;
  }
  else {
    return $ip;
  }
}