You are here

public function EventController::asTableRow in MongoDB 8.2

Provide a table row representation of an event occurrence.

Parameters

\Drupal\mongodb_watchdog\EventTemplate $template: The template for which the occurrence exists.

\Drupal\mongodb_watchdog\Event $event: The event occurrence to represent.

Return value

array A render array.

Throws

\Drupal\Core\Entity\EntityMalformedException

File

modules/mongodb_watchdog/src/EventController.php, line 103

Class

EventController
Class EventController provides query and render logic for Event occurrences.

Namespace

Drupal\mongodb_watchdog

Code

public function asTableRow(EventTemplate $template, Event $event) : array {
  $uid = $event
    ->uid();
  if (!isset($this->userCache[$uid])) {
    $this->userCache[$uid] = $uid ? User::load($uid)
      ->toLink() : $this->anonymous;
  }
  $location = $event
    ->location();
  $ret = [
    $this->dateFormatter
      ->format($event->timestamp, 'short'),
    $this->userCache[$uid],
    $template
      ->asString($event->variables),
    // Locations generated from Drush/Console will not necessarily match the
    // site home URL, and will not therefore not necessarily be reachable, so
    // we only generate a link if the location is "within" the site.
    mb_strpos($location, $this->front) === 0 ? Link::fromTextAndUrl(mb_substr($location, $this->baseLength), Url::fromUri($location)) : $location,
    empty($event->referrer) ? '' : Link::fromTextAndUrl($event->referrer, Url::fromUri($event->referrer)),
    $event->hostname,
    isset($event->requestTracking_id) ? Link::createFromRoute($this
      ->t('Request'), 'mongodb_watchdog.reports.request', [
      'uniqueId' => $event->requestTracking_id,
    ]) : '',
  ];
  return $ret;
}