You are here

public function DbLogController::eventDetails in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::eventDetails()

Displays details about a specific database log message.

Parameters

int $event_id: Unique ID of the database log message.

Return value

array If the ID is located in the Database Logging table, a build array in the format expected by drupal_render();

1 string reference to 'DbLogController::eventDetails'
dblog.routing.yml in core/modules/dblog/dblog.routing.yml
core/modules/dblog/dblog.routing.yml

File

core/modules/dblog/src/Controller/DbLogController.php, line 244
Contains \Drupal\dblog\Controller\DbLogController.

Class

DbLogController
Returns responses for dblog routes.

Namespace

Drupal\dblog\Controller

Code

public function eventDetails($event_id) {
  $build = array();
  if ($dblog = $this->database
    ->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', array(
    ':id' => $event_id,
  ))
    ->fetchObject()) {
    $severity = RfcLogLevel::getLevels();
    $message = $this
      ->formatMessage($dblog);
    $username = array(
      '#theme' => 'username',
      '#account' => $dblog->uid ? $this->userStorage
        ->load($dblog->uid) : User::getAnonymousUser(),
    );
    $rows = array(
      array(
        array(
          'data' => $this
            ->t('Type'),
          'header' => TRUE,
        ),
        $this
          ->t($dblog->type),
      ),
      array(
        array(
          'data' => $this
            ->t('Date'),
          'header' => TRUE,
        ),
        $this->dateFormatter
          ->format($dblog->timestamp, 'long'),
      ),
      array(
        array(
          'data' => $this
            ->t('User'),
          'header' => TRUE,
        ),
        array(
          'data' => $username,
        ),
      ),
      array(
        array(
          'data' => $this
            ->t('Location'),
          'header' => TRUE,
        ),
        $this
          ->l($dblog->location, $dblog->location ? Url::fromUri($dblog->location) : Url::fromRoute('<none>')),
      ),
      array(
        array(
          'data' => $this
            ->t('Referrer'),
          'header' => TRUE,
        ),
        $this
          ->l($dblog->referer, $dblog->referer ? Url::fromUri($dblog->referer) : Url::fromRoute('<none>')),
      ),
      array(
        array(
          'data' => $this
            ->t('Message'),
          'header' => TRUE,
        ),
        $message,
      ),
      array(
        array(
          'data' => $this
            ->t('Severity'),
          'header' => TRUE,
        ),
        $severity[$dblog->severity],
      ),
      array(
        array(
          'data' => $this
            ->t('Hostname'),
          'header' => TRUE,
        ),
        $dblog->hostname,
      ),
      array(
        array(
          'data' => $this
            ->t('Operations'),
          'header' => TRUE,
        ),
        array(
          'data' => array(
            '#markup' => $dblog->link,
          ),
        ),
      ),
    );
    $build['dblog_table'] = array(
      '#type' => 'table',
      '#rows' => $rows,
      '#attributes' => array(
        'class' => array(
          'dblog-event',
        ),
      ),
      '#attached' => array(
        'library' => array(
          'dblog/drupal.dblog',
        ),
      ),
    );
  }
  return $build;
}