class WebformSubmissionLogController in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_submission_log/src/Controller/WebformSubmissionLogController.php \Drupal\webform_submission_log\Controller\WebformSubmissionLogController
Returns responses for webform submission log routes.
Copied from: \Drupal\dblog\Controller\DbLogController.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\webform_submission_log\Controller\WebformSubmissionLogController
Expanded class hierarchy of WebformSubmissionLogController
File
- modules/
webform_submission_log/ src/ Controller/ WebformSubmissionLogController.php, line 21
Namespace
Drupal\webform_submission_log\ControllerView source
class WebformSubmissionLogController extends ControllerBase {
/**
* The database service.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* The user storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* The webform storage.
*
* @var \Drupal\webform\WebformEntityStorageInterface
*/
protected $webformStorage;
/**
* The webform submission storage.
*
* @var \Drupal\webform\WebformSubmissionStorageInterface
*/
protected $webformSubmissionStorage;
/**
* The webform request handler.
*
* @var \Drupal\webform\WebformRequestInterface
*/
protected $requestHandler;
/**
* The webform submission log manager.
*
* @var \Drupal\webform_submission_log\WebformSubmissionLogManagerInterface
*/
protected $logManager;
/**
* Constructs a WebformSubmissionLogController object.
*
* @param \Drupal\Core\Database\Connection $database
* A database connection.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\webform\WebformRequestInterface $request_handler
* The webform request handler.
* @param \Drupal\webform_submission_log\WebformSubmissionLogManagerInterface $log_manager
* The webform submission log manager.
*/
public function __construct(Connection $database, DateFormatterInterface $date_formatter, WebformRequestInterface $request_handler, WebformSubmissionLogManagerInterface $log_manager) {
$this->database = $database;
$this->dateFormatter = $date_formatter;
$this->webformStorage = $this
->entityTypeManager()
->getStorage('webform');
$this->webformSubmissionStorage = $this
->entityTypeManager()
->getStorage('webform_submission');
$this->userStorage = $this
->entityTypeManager()
->getStorage('user');
$this->requestHandler = $request_handler;
$this->logManager = $log_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('date.formatter'), $container
->get('webform.request'), $container
->get('webform_submission_log.manager'));
}
/**
* Displays a listing of webform submission log messages.
*
* @param \Drupal\webform\WebformInterface|null $webform
* A webform.
* @param \Drupal\webform\WebformSubmissionInterface|null $webform_submission
* A webform submission.
* @param \Drupal\Core\Entity\EntityInterface|null $source_entity
* A source entity.
* @param \Drupal\Core\Session\AccountInterface|null $account
* A user account.
*
* @return array
* A render array as expected by drupal_render().
*/
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->webformStorage
->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->webformSubmissionStorage
->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->userStorage
->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;
}
/**
* Wrapper that allows the $node to be used as $source_entity.
*/
public function nodeOverview(WebformInterface $webform = NULL, WebformSubmissionInterface $webform_submission = NULL, EntityInterface $node = NULL) {
return $this
->overview($webform, $webform_submission, $node);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
WebformSubmissionLogController:: |
protected | property | The database service. | |
WebformSubmissionLogController:: |
protected | property | The date formatter service. | |
WebformSubmissionLogController:: |
protected | property | The webform submission log manager. | |
WebformSubmissionLogController:: |
protected | property | The webform request handler. | |
WebformSubmissionLogController:: |
protected | property | The user storage. | |
WebformSubmissionLogController:: |
protected | property | The webform storage. | |
WebformSubmissionLogController:: |
protected | property | The webform submission storage. | |
WebformSubmissionLogController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
WebformSubmissionLogController:: |
public | function | Wrapper that allows the $node to be used as $source_entity. | |
WebformSubmissionLogController:: |
public | function | Displays a listing of webform submission log messages. | |
WebformSubmissionLogController:: |
public | function | Constructs a WebformSubmissionLogController object. |