Skip to content

Commit 5924d6c

Browse files
committed
ITKDev: Better handling of CPR fields audit
1 parent d4e0e7f commit 5924d6c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

modules/os2web_audit_entity/os2web_audit_entity.module

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,24 @@ function os2web_audit_entity_webform_post_load_data(mixed $submissions): void {
5757
foreach ($submissions as $submission) {
5858
// Try to check for _cpr field for extra logging information.
5959
$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+
6073
$submissionData = $submission->getData();
61-
$filterFields = preg_grep('/^(.*)cpr(.*)$/', array_keys($submissionData));
6274
if (!empty($filterFields)) {
6375
foreach ($filterFields as $field) {
6476
$cpr = $submissionData[$field];
65-
$personal .= sprintf('CPR "%s".', $cpr);
77+
$personal .= sprintf(' CPR "%s" in field "%s".', $cpr ?: 'null', $field);
6678
}
6779
}
6880

@@ -71,16 +83,15 @@ function os2web_audit_entity_webform_post_load_data(mixed $submissions): void {
7183
if (preg_match('~(.*)/print/pdf/(.*)|(.*)\d.*/attachment(.*)~', $request->getPathInfo())) {
7284
// We know that a webform submission has been loaded and this is a print
7385
// 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());
7587
os2web_audit_entity_log($msg);
7688

7789
// Exit to prevent double log entry.
7890
return;
7991
}
8092

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());
8294
os2web_audit_entity_log($msg);
83-
8495
}
8596
}
8697

0 commit comments

Comments
 (0)