function DbLogController::formatMessage

Same name in other branches
  1. 8.9.x core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::formatMessage()
  2. 10 core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::formatMessage()
  3. 11.x core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::formatMessage()

Formats a database log message.

Parameters

object $row: The record from the watchdog table. The object properties are: wid, uid, severity, type, timestamp, message, variables, link, name.

Return value

string|\Drupal\Core\StringTranslation\TranslatableMarkup|false The formatted log message or FALSE if the message or variables properties are not set.

3 calls to DbLogController::formatMessage()
DbLogController::eventDetails in core/modules/dblog/src/Controller/DbLogController.php
Displays details about a specific database log message.
DbLogController::overview in core/modules/dblog/src/Controller/DbLogController.php
Displays a listing of database log messages.
DbLogController::topLogMessages in core/modules/dblog/src/Controller/DbLogController.php
Shows the most frequent log messages of a given event type.

File

core/modules/dblog/src/Controller/DbLogController.php, line 357

Class

DbLogController
Returns responses for dblog routes.

Namespace

Drupal\dblog\Controller

Code

public function formatMessage($row) {
    // Check for required properties.
    if (isset($row->message, $row->variables)) {
        $variables = @unserialize($row->variables);
        // Messages without variables or user specified text.
        if ($variables === NULL) {
            $message = Xss::filterAdmin($row->message);
        }
        elseif (!is_array($variables)) {
            $message = $this->t('Log data is corrupted and cannot be unserialized: @message', [
                '@message' => Xss::filterAdmin($row->message),
            ]);
        }
        else {
            // Ensure backtrace strings are properly formatted.
            if (isset($variables['@backtrace_string'])) {
                $variables['@backtrace_string'] = new FormattableMarkup('<pre class="backtrace">@backtrace_string</pre>', $variables);
            }
            $message = $this->t(Xss::filterAdmin($row->message), $variables);
        }
    }
    else {
        $message = FALSE;
    }
    return $message;
}

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