You are here

public function AutobanAnalyzeForm::formatMessage in Automatic IP ban (Autoban) 8

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.

1 call to AutobanAnalyzeForm::formatMessage()
AutobanAnalyzeForm::buildForm in src/Form/AutobanAnalyzeForm.php
Form constructor.

File

src/Form/AutobanAnalyzeForm.php, line 279

Class

AutobanAnalyzeForm
Analyze watchdog entries for IP addresses for ban.

Namespace

Drupal\autoban\Form

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 {
      $message = $this
        ->t(Xss::filterAdmin($row->message), $variables);
    }
  }
  else {
    $message = '';
  }
  return $message;
}