You are here

admin_audit_trail_file.module in Admin Audit Trail 1.0.x

Logs file entity CUD commands in the admin_audit_trail module.

File

admin_audit_trail_file/admin_audit_trail_file.module
View source
<?php

/**
 * @file
 * Logs file entity CUD commands in the admin_audit_trail module.
 */
use Drupal\Core\Entity\EntityInterface;

/**
 * Implements hook_admin_audit_trail_handlers().
 */
function admin_audit_trail_file_admin_audit_trail_handlers() {
  $handlers = [];

  // File event log handler.
  $handlers['file'] = [
    'title' => t('File'),
  ];
  return $handlers;
}

/**
 * Implements hook_ENTITY_TYPE_insert().
 */
function admin_audit_trail_file_insert(EntityInterface $entity) {
  $log = [
    'type' => 'file',
    'operation' => 'insert',
    'description' => $entity
      ->getFileUri(),
    'ref_numeric' => $entity
      ->id(),
    'ref_char' => $entity
      ->getFilename(),
  ];

  // Insert log.
  admin_audit_trail_insert($log);
}

/**
 * Implements hook_ENTITY_TYPE_update().
 */
function admin_audit_trail_file_update(EntityInterface $entity) {
  $log = [
    'type' => 'file',
    'operation' => 'update',
    'description' => $entity
      ->getFileUri(),
    'ref_numeric' => $entity
      ->id(),
    'ref_char' => $entity
      ->getFilename(),
  ];

  // Insert log.
  admin_audit_trail_insert($log);
}

/**
 * Implements hook_ENTITY_TYPE_delete().
 */
function admin_audit_trail_file_delete(EntityInterface $entity) {
  $log = [
    'type' => 'file',
    'operation' => 'delete',
    'description' => $entity
      ->getFileUri(),
    'ref_numeric' => $entity
      ->id(),
    'ref_char' => $entity
      ->getFilename(),
  ];

  // Insert log.
  admin_audit_trail_insert($log);
}