You are here

private function AdvbanSearchForm::searchResult in Advanced ban 8

Make table formatted search result.

Parameters

object $ip: IP entry object.

Return value

array Row for table formatter.

1 call to AdvbanSearchForm::searchResult()
AdvbanSearchForm::buildForm in src/Form/AdvbanSearchForm.php
Form constructor.

File

src/Form/AdvbanSearchForm.php, line 175

Class

AdvbanSearchForm
Search banned IP addresses.

Namespace

Drupal\advban\Form

Code

private function searchResult($ip) {
  $row = [];
  $row[] = $this->ipManager
    ->formatIp($ip->ip, $ip->ip_end);
  $row[] = empty($ip->expiry_date) ? $this
    ->t('Never') : $this->dateFormatter
    ->format($ip->expiry_date);
  $status = $this
    ->t('Banned');
  if (!empty($ip->expiry_date) && $ip->expiry_date <= $this->time
    ->getRequestTime()) {

    // This IP is not banned and this advban entry will be deleted by cron.
    $status = $this
      ->t('Expired');
  }
  $row[] = $status;
  $destination = $this
    ->getDestinationArray();
  $url_destination = [
    'destination' => $destination['destination'],
  ];
  $query = [
    'query' => [
      $url_destination,
    ],
  ];
  $links = [];
  $links['edit'] = [
    'title' => $this
      ->t('Edit'),
    'url' => Url::fromRoute('advban.admin_page', [
      'ban_id' => $ip->iid,
    ], $query),
  ];
  $links['delete'] = [
    'title' => $this
      ->t('Delete'),
    'url' => Url::fromRoute('advban.delete', [
      'ban_id' => $ip->iid,
    ], $query),
  ];
  $row[] = [
    'data' => [
      '#type' => 'operations',
      '#links' => $links,
    ],
  ];
  return $row;
}