Currently if I have logging enabled and make a change to a submission, I get:

MySQL [drupal]> select * from webform_submission_log;
+-----+------------+------+------------+-----+--------------------+---------------------------------+--------+------------+
| lid | webform_id | sid  | handler_id | uid | operation          | message                         | data   | timestamp  |
+-----+------------+------+------------+-----+--------------------+---------------------------------+--------+------------+
|   1 | contact    |    1 |            |   1 | submission updated | Contact: Submission #1 updated. | a:0:{} | 1526142025 |

Instead of the data being an empty array, what would be the best way to track data which would look something like:

[
  'changed' => [
    'email' => [
      'before' => 'whatever@example.com',
      'after' => 'something_else@example.com',
  ],
],

Is there a plugin I can implement in my module, or should I submit a patch to webform for this?

Any guidance appreciated as to the best way to accomplish this, thanks!

Comments

alberto56 created an issue. See original summary.

jrockowitz’s picture

Status: Active » Postponed

We need to improve webform module's logging API and implementation before adding any new functionality is implemented

https://www.drupal.org/project/issues/webform?text=log&version=8.x

alberto56’s picture

Hi, thanks for the info.

I needed this functionality so I wrote a small patch which provides just the information I need. I have not set this to "needs review", as this patch is not extensible and I don't expect it to be added to the module. Nonetheless, here it is in case someone might have a need for it.

Cheers,

Albert

jrockowitz’s picture

@alberto56 This is a great patch to have available for other users. Thanks

alberto56’s picture

An example usecase for this can be found at https://www.drupal.org/project/webform_submission_change_history

jrockowitz’s picture

Status: Postponed » Closed (outdated)

Creating a dedicated module makes sense.

I added a link to your module from the Webform: Add-ons tab (/admin/structure/webform/addons) and documentation

I am going to close this ticket

alberto56’s picture

Thanks for the quick feedback.

Once #2946132: Improve API for working with submission log entries is fixed, it should be possible for that module to work without the patch.

alberto56’s picture

StatusFileSize
new1.88 KB

Here is another version of this patch which does not assume that a field key exists in submissions. Leaving the issue Closed because this patch is a stopgap measure until #2946132: Improve API for working with submission log entries is fixed.

alberto56’s picture

The patch at #8 no longer applies since commit [3f9f3ad](https://cgit.drupalcode.org/webform/commit/?id=3f9f3ad) which fixes #3015180: Add 'webform_submission_log' submodule.
Therefore the patch at #8 applies to version 8.x-5.0-rc29 or before of Webform.

Here is a patch which applies to version 8.x-5.0-rc30 or after of Webform.

I will also, in the coming minutes, update https://www.drupal.org/project/webform_submission_change_history to be compatible with Webform 8.x-5.0-rc30 and later.

I am leaving the patch at #8 visible in case anyone is using Webform 8.x-5.0-rc29 and requires that patch.

alberto56’s picture

in #3106955: [Webform 6.x] Remove deprecated code the log() method was removed from ./src/WebformSubmissionStorage.php, so the patch no longer applies in 6.x. I will no longer maintain https://www.drupal.org/project/webform_submission_change_history and have added a note to that effect in the module page and the Webform Add-Ons documentation page (my one-line change made a bunch of unexplained changes to the markup, but that did not seem to modify the content or layout of the page).