public function WebformSubmissionLogController::overview in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_submission_log/src/Controller/WebformSubmissionLogController.php \Drupal\webform_submission_log\Controller\WebformSubmissionLogController::overview()
Displays a listing of webform submission log messages.
Parameters
\Drupal\webform\WebformInterface|null $webform: A webform.
\Drupal\webform\WebformSubmissionInterface|null $webform_submission: A webform submission.
\Drupal\Core\Entity\EntityInterface|null $source_entity: A source entity.
\Drupal\Core\Session\AccountInterface|null $account: A user account.
Return value
array A render array as expected by drupal_render().
1 call to WebformSubmissionLogController::overview()
- WebformSubmissionLogController::nodeOverview in modules/
webform_submission_log/ src/ Controller/ WebformSubmissionLogController.php - Wrapper that allows the $node to be used as $source_entity.
1 string reference to 'WebformSubmissionLogController::overview'
- webform_submission_log.routing.yml in modules/
webform_submission_log/ webform_submission_log.routing.yml - modules/webform_submission_log/webform_submission_log.routing.yml
File
- modules/
webform_submission_log/ src/ Controller/ WebformSubmissionLogController.php, line 79
Class
- WebformSubmissionLogController
- Returns responses for webform submission log routes.
Namespace
Drupal\webform_submission_log\ControllerCode
public function overview(WebformInterface $webform = NULL, WebformSubmissionInterface $webform_submission = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
// Entities.
if (empty($webform) && !empty($webform_submission)) {
$webform = $webform_submission
->getWebform();
}
if (empty($source_entity) && !empty($webform_submission)) {
$source_entity = $webform_submission
->getSourceEntity();
}
$webform_entity = $webform_submission ?: $webform;
// Header.
$header = [];
$header['lid'] = [
'data' => $this
->t('#'),
'field' => 'log.lid',
'sort' => 'desc',
];
if (empty($webform)) {
$header['webform_id'] = [
'data' => $this
->t('Webform'),
'field' => 'log.webform_id',
'class' => [
RESPONSIVE_PRIORITY_MEDIUM,
],
];
}
if (empty($source_entity) && empty($webform_submission)) {
$header['entity'] = [
'data' => $this
->t('Submitted to'),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
}
if (empty($webform_submission)) {
$header['sid'] = [
'data' => $this
->t('Submission'),
'field' => 'log.sid',
];
}
$header['handler_id'] = [
'data' => $this
->t('Handler'),
'field' => 'log.handler_id',
];
$header['operation'] = [
'data' => $this
->t('Operation'),
'field' => 'log.operation',
'class' => [
RESPONSIVE_PRIORITY_MEDIUM,
],
];
$header['message'] = [
'data' => $this
->t('Message'),
'field' => 'log.message',
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
$header['uid'] = [
'data' => $this
->t('User'),
'field' => 'user.name',
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
$header['timestamp'] = [
'data' => $this
->t('Date'),
'field' => 'log.timestamp',
'sort' => 'desc',
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
// Query.
$options = [
'header' => $header,
'limit' => 50,
];
$logs = $this->logManager
->loadByEntities($webform_entity, $source_entity, $account, $options);
// Rows.
$rows = [];
foreach ($logs as $log) {
$row = [];
$row['lid'] = $log->lid;
if (empty($webform)) {
$log_webform = $this
->getWebformStorage()
->load($log->webform_id);
$row['webform_id'] = $log_webform
->toLink($log_webform
->label(), 'results-log');
}
if (empty($source_entity) && empty($webform_submission)) {
$entity = NULL;
if ($log->entity_type && $log->entity_id) {
$entity_type = $log->entity_type;
$entity_id = $log->entity_id;
if ($entity = $this
->entityTypeManager()
->getStorage($entity_type)
->load($entity_id)) {
$row['entity'] = $entity
->hasLinkTemplate('canonical') ? $entity
->toLink() : "{$entity_type}:{$entity_id}";
}
else {
$row['entity'] = "{$entity_type}:{$entity_id}";
}
}
else {
$row['entity'] = '';
}
}
if (empty($webform_submission)) {
if ($log->sid) {
$log_webform_submission = $this
->getSubmissionStorage()
->load($log->sid);
$row['sid'] = [
'data' => [
'#type' => 'link',
'#title' => $log->sid,
'#url' => $this->requestHandler
->getUrl($log_webform_submission, $source_entity, 'webform_submission.log'),
],
];
}
else {
$row['sid'] = '';
}
}
$row['handler_id'] = $log->handler_id;
$row['operation'] = $log->operation;
$row['message'] = [
'data' => [
'#markup' => $this
->t($log->message, $log->variables),
],
];
$row['uid'] = [
'data' => [
'#theme' => 'username',
'#account' => $this
->getEntityStorage('user')
->load($log->uid),
],
];
$row['timestamp'] = $this->dateFormatter
->format($log->timestamp, 'short');
$rows[] = $row;
}
$build['table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#sticky' => TRUE,
'#empty' => $this
->t('No log messages available.'),
];
$build['pager'] = [
'#type' => 'pager',
];
return $build;
}