diff --git a/includes/webform.install.update.inc b/includes/webform.install.update.inc
index e1fbaa07..ebac4d8d 100644
--- a/includes/webform.install.update.inc
+++ b/includes/webform.install.update.inc
@@ -2895,3 +2895,26 @@ function webform_update_8155() {
}
}
}
+
+/**
+ * Issue #3015180: Add 'webform_submission_log' submodule.
+ */
+function webform_update_8156() {
+ $enable = \Drupal::config('webform.settings')->get('settings.default_submission_log');
+ if (!$enable) {
+ $query = \Drupal::entityQuery('webform')
+ ->condition('settings.submission_log', TRUE)
+ ->count();
+ $enable = $query->execute() > 0;
+ }
+
+ if ($enable) {
+ try {
+ \Drupal::service('module_installer')->install(['webform_submission_log']);
+ }
+ catch (\Drupal\Core\Database\SchemaObjectExistsException $exception) {
+ // This is actually expected. The table {webform_submission_log} would exist
+ // from webform submission entity schema.
+ }
+ }
+}
diff --git a/modules/webform_node/src/Controller/WebformNodeSubmissionLogController.php b/modules/webform_node/src/Controller/WebformNodeSubmissionLogController.php
deleted file mode 100644
index d20a4b78..00000000
--- a/modules/webform_node/src/Controller/WebformNodeSubmissionLogController.php
+++ /dev/null
@@ -1,22 +0,0 @@
-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;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('database'),
+ $container->get('date.formatter'),
+ $container->get('webform.request')
+ );
+ }
+
+ /**
+ * 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.
+ *
+ * @return array
+ * A render array as expected by drupal_render().
+ */
+ public function overview(WebformInterface $webform = NULL, WebformSubmissionInterface $webform_submission = NULL, EntityInterface $source_entity = NULL) {
+ if (empty($webform) && !empty($webform_submission)) {
+ $webform = $webform_submission->getWebform();
+ }
+ if (empty($source_entity) && !empty($webform_submission)) {
+ $source_entity = $webform_submission->getSourceEntity();
+ }
+
+ // Header.
+ $header = [];
+ $header['lid'] = ['data' => $this->t('#'), 'field' => 'l.lid', 'sort' => 'desc'];
+ if (empty($webform)) {
+ $header['webform_id'] = ['data' => $this->t('Webform'), 'field' => 'l.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' => 'l.sid'];
+ }
+ $header['handler_id'] = ['data' => $this->t('Handler'), 'field' => 'l.handler_id'];
+ $header['operation'] = ['data' => $this->t('Operation'), 'field' => 'l.operation', 'class' => [RESPONSIVE_PRIORITY_MEDIUM]];
+ $header['message'] = ['data' => $this->t('Message'), 'field' => 'l.message', 'class' => [RESPONSIVE_PRIORITY_LOW]];
+ $header['uid'] = ['data' => $this->t('User'), 'field' => 'ufd.name', 'class' => [RESPONSIVE_PRIORITY_LOW]];
+ $header['timestamp'] = ['data' => $this->t('Date'), 'field' => 'l.timestamp', 'sort' => 'desc', 'class' => [RESPONSIVE_PRIORITY_LOW]];
+
+ // Query.
+ $query = $this->database->select('webform_submission_log', 'l')
+ ->extend('\Drupal\Core\Database\Query\PagerSelectExtender')
+ ->extend('\Drupal\Core\Database\Query\TableSortExtender');
+ $query->leftJoin('users_field_data', 'ufd', 'l.uid = ufd.uid');
+ $query->leftJoin('webform_submission', 'ws', 'l.sid = ws.sid');
+ $query->fields('l', [
+ 'lid',
+ 'uid',
+ 'webform_id',
+ 'sid',
+ 'handler_id',
+ 'operation',
+ 'message',
+ 'timestamp',
+ ]);
+ $query->fields('ws', [
+ 'entity_type',
+ 'entity_id',
+ ]);
+ if ($webform) {
+ $query->condition('l.webform_id', $webform->id());
+ }
+ if ($webform_submission) {
+ $query->condition('l.sid', $webform_submission->id());
+ }
+ if ($source_entity) {
+ $query->condition('ws.entity_type', $source_entity->getEntityTypeId());
+ $query->condition('ws.entity_id', $source_entity->id());
+ }
+ $result = $query
+ ->limit(50)
+ ->orderByHeader($header)
+ ->execute();
+
+ // Rows.
+ $rows = [];
+ foreach ($result 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' => $log->message,
+ ],
+ ];
+ $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);
+ }
+
+}
diff --git a/modules/webform_node/src/Tests/WebformNodeSubmissionLogTest.php b/modules/webform_submission_log/src/Tests/WebformSubmissionLogNodeTest.php
similarity index 85%
rename from modules/webform_node/src/Tests/WebformNodeSubmissionLogTest.php
rename to modules/webform_submission_log/src/Tests/WebformSubmissionLogNodeTest.php
index 00978dd5..836fb020 100644
--- a/modules/webform_node/src/Tests/WebformNodeSubmissionLogTest.php
+++ b/modules/webform_submission_log/src/Tests/WebformSubmissionLogNodeTest.php
@@ -1,20 +1,22 @@
database = $datababse;
+ $this->parser = $parser;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function log($level, $message, array $context = []) {
+ if ($context['channel'] != 'webform_submission_log') {
+ // We log nothing but the webform submission logs.
+ return;
+ }
+
+ if (!isset($context['webform_submission'])) {
+ return;
+ }
+
+ // Remove unneeded context.
+ unset($context['backtrace']);
+
+ /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
+ $webform_submission = $context['webform_submission'];
+
+ if ($webform_submission->getWebform()->hasSubmissionLog()) {
+ $message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
+
+ $this->database->insert(self::TABLE)
+ ->fields([
+ 'webform_id' => $webform_submission->getWebform()->id(),
+ 'sid' => $webform_submission->id(),
+ 'handler_id' => isset($context['handler_id']) ? $context['handler_id'] : '',
+ 'operation' => isset($context['operation']) ? $context['operation'] : '',
+ 'uid' => $context['uid'],
+ 'message' => $message,
+ 'data' => serialize($message_placeholders),
+ 'timestamp' => $context['timestamp'],
+ ])
+ ->execute();
+ }
+ }
+
+}
diff --git a/modules/webform_submission_log/webform_submission_log.info.yml b/modules/webform_submission_log/webform_submission_log.info.yml
new file mode 100644
index 00000000..7c918fb0
--- /dev/null
+++ b/modules/webform_submission_log/webform_submission_log.info.yml
@@ -0,0 +1,7 @@
+name: Webform submission log
+type: module
+description: 'Dedicated logging for webform submissions.'
+package: Webform
+core: 8.x
+dependencies:
+ - 'webform:webform'
diff --git a/modules/webform_submission_log/webform_submission_log.install b/modules/webform_submission_log/webform_submission_log.install
new file mode 100644
index 00000000..c9c36c57
--- /dev/null
+++ b/modules/webform_submission_log/webform_submission_log.install
@@ -0,0 +1,84 @@
+ 'Table that contains logs of all webform submission events.',
+ 'fields' => [
+ 'lid' => [
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => 'Primary Key: Unique log event ID.',
+ ],
+ 'webform_id' => [
+ 'description' => 'The webform id.',
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => TRUE,
+ ],
+ 'sid' => [
+ 'description' => 'The webform submission id.',
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => FALSE,
+ ],
+ 'handler_id' => [
+ 'description' => 'The webform handler id.',
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => FALSE,
+ ],
+ 'uid' => [
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The {users}.uid of the user who triggered the event.',
+ ],
+ 'operation' => [
+ 'type' => 'varchar_ascii',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Type of operation, for example "save", "sent", or "update."',
+ ],
+ 'message' => [
+ 'type' => 'text',
+ 'not null' => TRUE,
+ 'size' => 'big',
+ 'description' => 'Text of log message.',
+ ],
+ 'data' => [
+ 'type' => 'blob',
+ 'not null' => TRUE,
+ 'size' => 'big',
+ 'description' => 'Serialized array of data.',
+ ],
+ 'timestamp' => [
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'Unix timestamp of when event occurred.',
+ ],
+ ],
+ 'primary key' => ['lid'],
+ 'indexes' => [
+ 'webform_id' => ['webform_id'],
+ 'sid' => ['sid'],
+ 'uid' => ['uid'],
+ 'handler_id' => ['handler_id'],
+ 'handler_id_operation' => ['handler_id', 'operation'],
+ ],
+ ];
+
+ return $schema;
+}
diff --git a/modules/webform_submission_log/webform_submission_log.links.task.yml b/modules/webform_submission_log/webform_submission_log.links.task.yml
new file mode 100644
index 00000000..c13744da
--- /dev/null
+++ b/modules/webform_submission_log/webform_submission_log.links.task.yml
@@ -0,0 +1,23 @@
+entity.webform.results_log:
+ title: 'Log'
+ route_name: entity.webform.results_log
+ parent_id: entity.webform.results
+ weight: 30
+
+entity.webform_submission.collection_log:
+ title: 'Log'
+ route_name: entity.webform_submission.collection_log
+ parent_id: entity.webform_submission.collection
+ weight: 20
+
+entity.webform_submission.log:
+ title: 'Log'
+ route_name: entity.webform_submission.log
+ base_route: entity.webform_submission.canonical
+ weight: 40
+
+entity.node.webform.results_log:
+ title: 'Log'
+ route_name: entity.node.webform.results_log
+ parent_id: entity.node.webform.results
+ weight: 30
diff --git a/modules/webform_submission_log/webform_submission_log.module b/modules/webform_submission_log/webform_submission_log.module
new file mode 100644
index 00000000..94c10866
--- /dev/null
+++ b/modules/webform_submission_log/webform_submission_log.module
@@ -0,0 +1,37 @@
+delete('webform_submission_log')
+ ->condition('webform_id', $webform->id())
+ ->execute();
+}
+
+/**
+ * Implements hook_webform_submission_delete().
+ */
+function webform_submission_log_webform_submission_delete(WebformSubmissionInterface $webform_submission) {
+ \Drupal::database()->delete('webform_submission_log')
+ ->condition('sid', $webform_submission->id())
+ ->execute();
+}
+
+/**
+ * Implements hook_local_tasks_alter().
+ */
+function webform_submission_log_local_tasks_alter(&$local_tasks) {
+ // Remove webform node log if the webform_node.module is not installed.
+ if (!\Drupal::moduleHandler()->moduleExists('webform_node')) {
+ unset($local_tasks['entity.node.webform.results_log']);
+ }
+}
diff --git a/modules/webform_submission_log/webform_submission_log.permissions.yml b/modules/webform_submission_log/webform_submission_log.permissions.yml
new file mode 100644
index 00000000..b17ce68d
--- /dev/null
+++ b/modules/webform_submission_log/webform_submission_log.permissions.yml
@@ -0,0 +1,3 @@
+'access webform submission log':
+ title: 'Access the webform submission log'
+ description: 'Allows viewing of all submission events, if the user can access a webform''s results.'
diff --git a/modules/webform_submission_log/webform_submission_log.routing.yml b/modules/webform_submission_log/webform_submission_log.routing.yml
new file mode 100644
index 00000000..b0439284
--- /dev/null
+++ b/modules/webform_submission_log/webform_submission_log.routing.yml
@@ -0,0 +1,39 @@
+entity.webform.results_log:
+ path: '/admin/structure/webform/manage/{webform}/results/log'
+ defaults:
+ _controller: '\Drupal\webform_submission_log\Controller\WebformSubmissionLogController::overview'
+ _title_callback: '\Drupal\webform\Controller\WebformEntityController::title'
+ options:
+ parameters:
+ webform:
+ type: 'entity:webform'
+ requirements:
+ _permission: 'access webform submission log'
+ _entity_access: 'webform.submission_view_any'
+ _custom_access: '\Drupal\webform\Access\WebformEntityAccess:checkLogAccess'
+
+entity.webform_submission.log:
+ path: '/admin/structure/webform/manage/{webform}/submission/{webform_submission}/log'
+ defaults:
+ _controller: '\Drupal\webform_submission_log\Controller\WebformSubmissionLogController::overview'
+ _title_callback: '\Drupal\webform\Controller\WebformSubmissionViewController::title'
+ requirements:
+ _permission: 'access webform submission log'
+ _entity_access: 'webform_submission.view_any'
+ _custom_access: '\Drupal\webform\Access\WebformEntityAccess::checkLogAccess'
+
+entity.node.webform.results_log:
+ path: '/node/{node}/webform/results/log'
+ defaults:
+ _controller: '\Drupal\webform_submission_log\Controller\WebformSubmissionLogController::nodeOverview'
+ _title_callback: '\Drupal\Core\Entity\Controller\EntityController::title'
+ operation: webform_submission_view
+ entity_access: 'webform.submission_view_any'
+ options:
+ _admin_route: TRUE
+ parameters:
+ node:
+ type: 'entity:node'
+ requirements:
+ _permission: 'access webform submission log'
+ _custom_access: '\Drupal\webform_node\Access\WebformNodeAccess::checkWebformLogAccess'
diff --git a/modules/webform_submission_log/webform_submission_log.services.yml b/modules/webform_submission_log/webform_submission_log.services.yml
new file mode 100644
index 00000000..6a580542
--- /dev/null
+++ b/modules/webform_submission_log/webform_submission_log.services.yml
@@ -0,0 +1,7 @@
+services:
+
+ logger.webform_submission_log:
+ class: Drupal\webform_submission_log\WebformSubmissionLog
+ arguments: ['@database', '@logger.log_message_parser']
+ tags:
+ - { name: logger }
diff --git a/src/Controller/WebformSubmissionLogController.php b/src/Controller/WebformSubmissionLogController.php
index 11741c46..9e78f8d7 100644
--- a/src/Controller/WebformSubmissionLogController.php
+++ b/src/Controller/WebformSubmissionLogController.php
@@ -10,6 +10,7 @@ use Drupal\webform\WebformInterface;
use Drupal\webform\WebformRequestInterface;
use Drupal\webform\WebformSubmissionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Returns responses for webform submission log routes.
@@ -104,6 +105,10 @@ class WebformSubmissionLogController extends ControllerBase {
* A render array as expected by drupal_render().
*/
public function overview(WebformInterface $webform = NULL, WebformSubmissionInterface $webform_submission = NULL, EntityInterface $source_entity = NULL) {
+ if (!$this->moduleHandler()->moduleExists('webform_submission_log')) {
+ throw new NotFoundHttpException();
+ }
+
if (empty($webform) && !empty($webform_submission)) {
$webform = $webform_submission->getWebform();
}
diff --git a/src/EntitySettings/WebformEntitySettingsSubmissionsForm.php b/src/EntitySettings/WebformEntitySettingsSubmissionsForm.php
index 9793a79a..b232b982 100644
--- a/src/EntitySettings/WebformEntitySettingsSubmissionsForm.php
+++ b/src/EntitySettings/WebformEntitySettingsSubmissionsForm.php
@@ -2,6 +2,7 @@
namespace Drupal\webform\EntitySettings;
+use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\Entity\View;
@@ -17,6 +18,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class WebformEntitySettingsSubmissionsForm extends WebformEntitySettingsBaseForm {
+ /**
+ * The module handler.
+ *
+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
+ */
+ protected $moduleHandler;
+
/**
* The webform token manager.
*
@@ -27,10 +35,13 @@ class WebformEntitySettingsSubmissionsForm extends WebformEntitySettingsBaseForm
/**
* Constructs a WebformEntitySettingsForm.
*
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ * The module handler.
* @param \Drupal\webform\WebformTokenManagerInterface $token_manager
* The webform token manager.
*/
- public function __construct(WebformTokenManagerInterface $token_manager) {
+ public function __construct(ModuleHandlerInterface $module_handler, WebformTokenManagerInterface $token_manager) {
+ $this->moduleHandler = $module_handler;
$this->tokenManager = $token_manager;
}
@@ -39,6 +50,7 @@ class WebformEntitySettingsSubmissionsForm extends WebformEntitySettingsBaseForm
*/
public static function create(ContainerInterface $container) {
return new static(
+ $container->get('module_handler'),
$container->get('webform.token_manager')
);
}
@@ -321,6 +333,7 @@ class WebformEntitySettingsSubmissionsForm extends WebformEntitySettingsBaseForm
'title' => $this->t('Log submission events'),
'all_description' => $this->t('All submission event are being logged for all webforms'),
'form_description' => $this->t('If checked, events will be logged for submissions to this webform.'),
+ 'access' => $this->moduleHandler->moduleExists('webform_submission_log'),
],
];
$this->appendBehaviors($form['submission_behaviors'], $behavior_elements, $settings, $default_settings);
diff --git a/src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php b/src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php
index 3204cdcb..8c17dfdb 100644
--- a/src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php
+++ b/src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php
@@ -3,6 +3,7 @@
namespace Drupal\webform\Form\AdminConfig;
use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Element\WebformMessage;
use Drupal\webform\WebformTokenManagerInterface;
@@ -13,6 +14,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class WebformAdminConfigSubmissionsForm extends WebformAdminConfigBaseForm {
+ /**
+ * The module handler.
+ *
+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
+ */
+ protected $moduleHandler;
+
/**
* The webform token manager.
*
@@ -32,11 +40,14 @@ class WebformAdminConfigSubmissionsForm extends WebformAdminConfigBaseForm {
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ * The module handler.
* @param \Drupal\webform\WebformTokenManagerInterface $token_manager
* The webform token manager.
*/
- public function __construct(ConfigFactoryInterface $config_factory, WebformTokenManagerInterface $token_manager) {
+ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, WebformTokenManagerInterface $token_manager) {
parent::__construct($config_factory);
+ $this->moduleHandler = $module_handler;
$this->tokenManager = $token_manager;
}
@@ -46,6 +57,7 @@ class WebformAdminConfigSubmissionsForm extends WebformAdminConfigBaseForm {
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
+ $container->get('module_handler'),
$container->get('webform.token_manager')
);
}
@@ -119,6 +131,7 @@ class WebformAdminConfigSubmissionsForm extends WebformAdminConfigBaseForm {
'default_submission_log' => [
'title' => $this->t('Log all submission events for all webforms'),
'description' => $this->t('If checked, all submission events will be logged to dedicated submission log available to all webforms and submissions.'),
+ 'access' => $this->moduleHandler->moduleExists('webform_submission_log'),
],
];
foreach ($behavior_elements as $behavior_key => $behavior_element) {
@@ -128,6 +141,7 @@ class WebformAdminConfigSubmissionsForm extends WebformAdminConfigBaseForm {
'#description' => $behavior_element['description'],
'#return_value' => TRUE,
'#default_value' => $settings[$behavior_key],
+ '#access' => $behavior_element['access'],
];
}
diff --git a/src/Tests/WebformOptionsTest.php b/src/Tests/WebformOptionsTest.php
index 29b8127c..c54849fd 100644
--- a/src/Tests/WebformOptionsTest.php
+++ b/src/Tests/WebformOptionsTest.php
@@ -36,7 +36,6 @@ class WebformOptionsTest extends WebformTestBase {
'access site reports',
'administer site configuration',
'administer webform',
- 'access webform submission log',
'create webform',
'administer users',
]);
diff --git a/src/Tests/WebformResultsExportOptionsTest.php b/src/Tests/WebformResultsExportOptionsTest.php
index f4bf422f..b433d569 100644
--- a/src/Tests/WebformResultsExportOptionsTest.php
+++ b/src/Tests/WebformResultsExportOptionsTest.php
@@ -30,7 +30,6 @@ class WebformResultsExportOptionsTest extends WebformTestBase {
*/
public function testExportOptions() {
$admin_submission_user = $this->drupalCreateUser([
- 'access webform submission log',
'administer webform submission',
]);
diff --git a/src/WebformEntityStorage.php b/src/WebformEntityStorage.php
index 9b6ea1a5..6859fba1 100644
--- a/src/WebformEntityStorage.php
+++ b/src/WebformEntityStorage.php
@@ -139,9 +139,6 @@ class WebformEntityStorage extends ConfigEntityStorage implements WebformEntityS
foreach ($entities as $entity) {
$webform_ids[] = $entity->id();
}
- $this->database->delete('webform_submission_log')
- ->condition('webform_id', $webform_ids, 'IN')
- ->execute();
// Delete all webform records used to track next serial.
$this->database->delete('webform')
diff --git a/src/WebformSubmissionStorage.php b/src/WebformSubmissionStorage.php
index ada17f76..53edcacf 100644
--- a/src/WebformSubmissionStorage.php
+++ b/src/WebformSubmissionStorage.php
@@ -1071,9 +1071,6 @@ class WebformSubmissionStorage extends SqlContentEntityStorage implements Webfor
}
}
- // Delete submission log after all pre and post delete hooks are called.
- $this->deleteLog($entities);
-
// Log deleted.
foreach ($entities as $entity) {
\Drupal::logger('webform')
@@ -1319,35 +1316,18 @@ class WebformSubmissionStorage extends SqlContentEntityStorage implements Webfor
return;
}
+ $message = $values['message'];
+ unset($values['message']);
+
$values += [
'uid' => $this->currentUser->id(),
- 'webform_id' => $webform_submission->getWebform()->id(),
- 'sid' => $webform_submission->id() ?: NULL,
+ 'webform_submission' => $webform_submission,
'handler_id' => NULL,
'data' => [],
- 'timestamp' => time(),
+ 'link' => $webform_submission->toLink($this->t('Edit'), 'edit-form')->toString(),
];
- $values['data'] = serialize($values['data']);
- $this->database
- ->insert('webform_submission_log')
- ->fields($values)
- ->execute();
- }
- /**
- * Delete webform submission events from the 'webform_submission_log' table.
- *
- * @param array $webform_submissions
- * An array of webform submissions.
- */
- protected function deleteLog(array $webform_submissions) {
- $sids = [];
- foreach ($webform_submissions as $webform_submission) {
- $sids[$webform_submission->id()] = $webform_submission->id();
- }
- $this->database->delete('webform_submission_log')
- ->condition('sid', $sids, 'IN')
- ->execute();
+ \Drupal::logger('webform_submission_log')->info($message, $values);
}
/****************************************************************************/
diff --git a/src/WebformSubmissionStorageSchema.php b/src/WebformSubmissionStorageSchema.php
index 983411fb..c3705f9a 100644
--- a/src/WebformSubmissionStorageSchema.php
+++ b/src/WebformSubmissionStorageSchema.php
@@ -65,75 +65,6 @@ class WebformSubmissionStorageSchema extends SqlContentEntityStorageSchema {
],
];
- $schema['webform_submission_log'] = [
- 'description' => 'Table that contains logs of all webform submission events.',
- 'fields' => [
- 'lid' => [
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique log event ID.',
- ],
- 'webform_id' => [
- 'description' => 'The webform id.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- ],
- 'sid' => [
- 'description' => 'The webform submission id.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => FALSE,
- ],
- 'handler_id' => [
- 'description' => 'The webform handler id.',
- 'type' => 'varchar',
- 'length' => 64,
- 'not null' => FALSE,
- ],
- 'uid' => [
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The {users}.uid of the user who triggered the event.',
- ],
- 'operation' => [
- 'type' => 'varchar_ascii',
- 'length' => 64,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Type of operation, for example "save", "sent", or "update."',
- ],
- 'message' => [
- 'type' => 'text',
- 'not null' => TRUE,
- 'size' => 'big',
- 'description' => 'Text of log message.',
- ],
- 'data' => [
- 'type' => 'blob',
- 'not null' => TRUE,
- 'size' => 'big',
- 'description' => 'Serialized array of data.',
- ],
- 'timestamp' => [
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Unix timestamp of when event occurred.',
- ],
- ],
- 'primary key' => ['lid'],
- 'indexes' => [
- 'webform_id' => ['webform_id'],
- 'sid' => ['sid'],
- 'uid' => ['uid'],
- 'handler_id' => ['handler_id'],
- 'handler_id_operation' => ['handler_id', 'operation'],
- ],
- ];
-
return $schema;
}
diff --git a/webform.links.task.yml b/webform.links.task.yml
index ba98d6c2..1f1c5dc8 100644
--- a/webform.links.task.yml
+++ b/webform.links.task.yml
@@ -26,12 +26,6 @@ entity.webform_submission.collection_purge:
parent_id: entity.webform_submission.collection
weight: 10
-entity.webform_submission.collection_log:
- title: 'Log'
- route_name: entity.webform_submission.collection_log
- parent_id: entity.webform_submission.collection
- weight: 20
-
# Settings.
webform.config:
@@ -154,12 +148,6 @@ entity.webform.results_clear:
parent_id: entity.webform.results
weight: 20
-entity.webform.results_log:
- title: 'Log'
- route_name: entity.webform.results_log
- parent_id: entity.webform.results
- weight: 30
-
# Webform edit (build).
entity.webform.edit_form:
@@ -288,12 +276,6 @@ entity.webform_submission.resend_form:
base_route: entity.webform_submission.canonical
weight: 30
-entity.webform_submission.log:
- title: 'Log'
- route_name: entity.webform_submission.log
- base_route: entity.webform_submission.canonical
- weight: 40
-
# User Submission
entity.webform.user.submission:
diff --git a/webform.permissions.yml b/webform.permissions.yml
index e426277d..bd924cbf 100644
--- a/webform.permissions.yml
+++ b/webform.permissions.yml
@@ -1,9 +1,6 @@
'access webform overview':
title: 'Access the webform overview page'
description: 'Get an overview of all webforms.'
-'access webform submission log':
- title: 'Access the webform submission log'
- description: 'Allows viewing of all submission events, if the user can access a webform''s results.'
'access webform submission user':
title: 'Access the webform user submission page'
description: 'Allows a user to view their submissions via ''Submissions'' tab on their profile page.'
diff --git a/webform.routing.yml b/webform.routing.yml
index 6388a8db..a0a8c2cf 100644
--- a/webform.routing.yml
+++ b/webform.routing.yml
@@ -423,20 +423,6 @@ entity.webform.results_clear:
_entity_access: 'webform.submission_purge_any'
_custom_access: '\Drupal\webform\Access\WebformEntityAccess:checkResultsAccess'
-entity.webform.results_log:
- path: '/admin/structure/webform/manage/{webform}/results/log'
- defaults:
- _controller: '\Drupal\webform\Controller\WebformSubmissionLogController::overview'
- _title_callback: '\Drupal\webform\Controller\WebformEntityController::title'
- options:
- parameters:
- webform:
- type: 'entity:webform'
- requirements:
- _permission: 'access webform submission log'
- _entity_access: 'webform.submission_view_any'
- _custom_access: '\Drupal\webform\Access\WebformEntityAccess:checkLogAccess'
-
# Webform options
entity.webform_options.collection:
@@ -579,16 +565,6 @@ entity.webform_submission.yaml:
_permission: 'edit webform source'
_entity_access: 'webform_submission.view_any'
-entity.webform_submission.log:
- path: '/admin/structure/webform/manage/{webform}/submission/{webform_submission}/log'
- defaults:
- _controller: '\Drupal\webform\Controller\WebformSubmissionLogController::overview'
- _title_callback: '\Drupal\webform\Controller\WebformSubmissionViewController::title'
- requirements:
- _permission: 'access webform submission log'
- _entity_access: 'webform_submission.view_any'
- _custom_access: '\Drupal\webform\Access\WebformEntityAccess::checkLogAccess'
-
entity.webform_submission.edit_form:
path: '/admin/structure/webform/manage/{webform}/submission/{webform_submission}/edit'
defaults: