function DbLogController::eventDetails

Same name in other branches
  1. 9 core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::eventDetails()
  2. 8.9.x core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::eventDetails()
  3. 10 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\Core\Render\RendererInterface::render().

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException If no event found for the given ID.

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 229

Class

DbLogController
Returns responses for dblog routes.

Namespace

Drupal\dblog\Controller

Code

public function eventDetails($event_id) {
    $query = $this->database
        ->select('watchdog', 'w')
        ->fields('w')
        ->condition('w.wid', $event_id);
    $query->leftJoin('users', 'u', '[u].[uid] = [w].[uid]');
    $query->addField('u', 'uid', 'uid');
    $dblog = $query->execute()
        ->fetchObject();
    if (empty($dblog)) {
        throw new NotFoundHttpException();
    }
    $build = [];
    $severity = RfcLogLevel::getLevels();
    $message = $this->formatMessage($dblog);
    $username = [
        '#theme' => 'username',
        '#account' => $dblog->uid ? $this->userStorage
            ->load($dblog->uid) : User::getAnonymousUser(),
    ];
    $rows = [
        [
            [
                'data' => $this->t('Type'),
                'header' => TRUE,
            ],
            $this->t($dblog->type),
        ],
        [
            [
                'data' => $this->t('Date'),
                'header' => TRUE,
            ],
            $this->dateFormatter
                ->format($dblog->timestamp, 'long'),
        ],
        [
            [
                'data' => $this->t('User'),
                'header' => TRUE,
            ],
            [
                'data' => $username,
            ],
        ],
        [
            [
                'data' => $this->t('Location'),
                'header' => TRUE,
            ],
            $this->createLink($dblog->location),
        ],
        [
            [
                'data' => $this->t('Referrer'),
                'header' => TRUE,
            ],
            $this->createLink($dblog->referer),
        ],
        [
            [
                'data' => $this->t('Message'),
                'header' => TRUE,
            ],
            $message,
        ],
        [
            [
                'data' => $this->t('Severity'),
                'header' => TRUE,
            ],
            $severity[$dblog->severity],
        ],
        [
            [
                'data' => $this->t('Hostname'),
                'header' => TRUE,
            ],
            $dblog->hostname,
        ],
        [
            [
                'data' => $this->t('Operations'),
                'header' => TRUE,
            ],
            [
                'data' => [
                    '#markup' => $dblog->link,
                ],
            ],
        ],
    ];
    if (isset($dblog->backtrace)) {
        $rows[] = [
            [
                'data' => $this->t('Backtrace'),
                'header' => TRUE,
            ],
            $dblog->backtrace,
        ];
    }
    $build['dblog_table'] = [
        '#type' => 'table',
        '#rows' => $rows,
        '#attributes' => [
            'class' => [
                'dblog-event',
            ],
        ],
        '#attached' => [
            'library' => [
                'dblog/drupal.dblog',
            ],
        ],
    ];
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.