public function WebformSubmissionLogLogger::log in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_submission_log/src/WebformSubmissionLogLogger.php \Drupal\webform_submission_log\WebformSubmissionLogLogger::log()
Overrides RfcLoggerTrait::log
File
- modules/
webform_submission_log/ src/ WebformSubmissionLogLogger.php, line 46
Class
- WebformSubmissionLogLogger
- Logger that listens for 'webform_submission' channel.
Namespace
Drupal\webform_submission_logCode
public function log($level, $message, array $context = []) {
// Only log the 'webform_submission' channel.
if ($context['channel'] !== 'webform_submission') {
return;
}
// Make sure the context contains a webform submission.
if (!isset($context['webform_submission'])) {
return;
}
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $context['webform_submission'];
// Make sure webform submission log is enabled.
if (!$webform_submission
->getWebform()
->hasSubmissionLog()) {
return;
}
// Set default values.
$context += [
'handler_id' => '',
'operation' => '',
'data' => [],
];
// Cast message to string.
$message = (string) $message;
$message_placeholders = $this->parser
->parseMessagePlaceholders($message, $context);
$this->logManager
->insert([
'webform_id' => $webform_submission
->getWebform()
->id(),
'sid' => $webform_submission
->id(),
'handler_id' => $context['handler_id'],
'operation' => $context['operation'],
'uid' => $context['uid'],
'message' => $message,
'variables' => serialize($message_placeholders),
'data' => serialize($context['data']),
'timestamp' => $context['timestamp'],
]);
}