@@ -57,12 +57,24 @@ function os2web_audit_entity_webform_post_load_data(mixed $submissions): void {
57
57
foreach ($submissions as $submission) {
58
58
// Try to check for _cpr field for extra logging information.
59
59
$personal = '';
60
+ $filterFields = [];
61
+
62
+ // Detect field of type that contains "cpr" in name or where field name
63
+ // contains "cpr".
64
+ /** @var \Drupal\webform_revisions\Entity\WebformRevisions $webform */
65
+ $webform = $submission->getWebform();
66
+ $elements = $webform->getElementsDecoded();
67
+ foreach ($elements as $fieldName => $element) {
68
+ if (str_contains(strtolower($element['#type']), 'cpr') || str_contains(strtolower($fieldName), 'cpr')) {
69
+ $filterFields[] = $fieldName;
70
+ }
71
+ }
72
+
60
73
$submissionData = $submission->getData();
61
- $filterFields = preg_grep('/^(.*)cpr(.*)$/', array_keys($submissionData));
62
74
if (!empty($filterFields)) {
63
75
foreach ($filterFields as $field) {
64
76
$cpr = $submissionData[$field];
65
- $personal .= sprintf('CPR "%s".', $cpr);
77
+ $personal .= sprintf(' CPR "%s" in field "%s" .', $cpr ?: 'null', $field );
66
78
}
67
79
}
68
80
@@ -71,16 +83,15 @@ function os2web_audit_entity_webform_post_load_data(mixed $submissions): void {
71
83
if (preg_match('~(.*)/print/pdf/(.*)|(.*)\d.*/attachment(.*)~', $request->getPathInfo())) {
72
84
// We know that a webform submission has been loaded and this is a print
73
85
// pdf path. This indicates that this is an attachment download action.
74
- $msg = sprintf('Webform submission (%d) downloaded as attachment. %s Webform id "%s".', $submission->id(), $personal, $submission->getWebform()->id());
86
+ $msg = sprintf('Webform submission (%d) downloaded as attachment.%s Webform id "%s".', $submission->id(), $personal, $submission->getWebform()->id());
75
87
os2web_audit_entity_log($msg);
76
88
77
89
// Exit to prevent double log entry.
78
90
return;
79
91
}
80
92
81
- $msg = sprintf('Webform submission (%d) looked up. %s Webform id "%s".', $submission->id(), $personal, $submission->getWebform()->id());
93
+ $msg = sprintf('Webform submission (%d) looked up.%s Webform id "%s".', $submission->id(), $personal, $submission->getWebform()->id());
82
94
os2web_audit_entity_log($msg);
83
-
84
95
}
85
96
}
86
97
0 commit comments