From e5cd3c2ad391c0fbd06663db165476d251cfeeaf Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Dec 2024 15:25:51 +0100 Subject: [PATCH] ITKDev: Added insert, update and delete entity logging --- .../os2web_audit_entity.install | 2 +- .../os2web_audit_entity.module | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/modules/os2web_audit_entity/os2web_audit_entity.install b/modules/os2web_audit_entity/os2web_audit_entity.install index 7879cc3..2737a3a 100644 --- a/modules/os2web_audit_entity/os2web_audit_entity.install +++ b/modules/os2web_audit_entity/os2web_audit_entity.install @@ -2,7 +2,7 @@ /** * @file - * This module enabled webform submission encryption as a default option. + * This module enabled os2web audit entity default options. */ /** diff --git a/modules/os2web_audit_entity/os2web_audit_entity.module b/modules/os2web_audit_entity/os2web_audit_entity.module index 83d241e..f908cca 100644 --- a/modules/os2web_audit_entity/os2web_audit_entity.module +++ b/modules/os2web_audit_entity/os2web_audit_entity.module @@ -1,9 +1,17 @@ id(), $entity->getEntityTypeId()); + os2web_audit_entity_log($msg); } /** * Implements hook_entity_update(). */ function os2web_audit_entity_entity_update(EntityInterface $entity): void { - // Your code to handle the entity update event. - $t = 1; + $msg = sprintf('Entity (%d) of type "%s" updated.', $entity->id(), $entity->getEntityTypeId()); + os2web_audit_entity_log($msg); } /** * Implements hook_entity_delete(). */ function os2web_audit_entity_entity_delete(EntityInterface $entity): void { - // Your code to handle the entity delete event. - + $msg = sprintf('Entity (%d) of type "%s" deleted.', $entity->id(), $entity->getEntityTypeId()); + os2web_audit_entity_log($msg); } +/** + * Implements hook_entity_storage_load(). + * + * Logs access for file entities. + */ function os2web_audit_entity_entity_storage_load(array $entities, $entity_type): void { foreach ($entities as $entity) { if ($entity_type == 'file') { @@ -94,6 +107,7 @@ function os2web_audit_entity_log(string $message): void { /** @var \Drupal\os2web_audit\Service\Logger $logger */ $logger = \Drupal::service('os2web_audit.logger'); + // Detect user type. $account = \Drupal::currentUser(); $apiUser = FALSE; if (os2web_audit_entity_is_api_user($account)) {