Skip to content

Commit

Permalink
ITKDev: Added insert, update and delete entity logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed Dec 11, 2024
1 parent a9d9ee1 commit e5cd3c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/os2web_audit_entity/os2web_audit_entity.install
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @file
* This module enabled webform submission encryption as a default option.
* This module enabled os2web audit entity default options.
*/

/**
Expand Down
26 changes: 20 additions & 6 deletions modules/os2web_audit_entity/os2web_audit_entity.module
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<?php

/**
* @file
* Hooks into drupal and collect logging data.
*/

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\webform_revisions\Entity\WebformRevisionsSubmission;

/**
* @TODO: Should this be configurable?
*/
const OS2WEB_AUDIT_ENTITY_API_USER_ROLES = [
'os2forms_rest_api_user',
'os2forms_rest_api_user_write',
Expand All @@ -13,26 +21,31 @@ const OS2WEB_AUDIT_ENTITY_USER_API = 'api';
const OS2WEB_AUDIT_ENTITY_USER_WEB = 'web';

function os2web_audit_entity_entity_insert(EntityInterface $entity): void {
// Your code to handle the entity update event.
$t = 1;
$msg = sprintf('Entity (%d) of type "%s" created.', $entity->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') {
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit e5cd3c2

Please sign in to comment.