You are here

function log_log_access in Log entity 8

Implements hook_log_access().

File

./log.module, line 92
Contains log.module..

Code

function log_log_access(LogInterface $log, $op, $account) {
  $type = $log
    ->bundle();
  switch ($op) {
    case 'view':
      if ($account
        ->hasPermission('view any ' . $type . ' log entities', $account)) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      else {
        return AccessResult::allowedIf($account
          ->hasPermission('view own ' . $type . ' log entities', $account) && $account
          ->id() == $log
          ->getOwnerId())
          ->cachePerPermissions()
          ->cachePerUser()
          ->cacheUntilEntityChanges($log);
      }
    case 'update':
      if ($account
        ->hasPermission('edit any ' . $type . ' log entities', $account)) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      else {
        return AccessResult::allowedIf($account
          ->hasPermission('edit own ' . $type . ' log entities', $account) && $account
          ->id() == $log
          ->getOwnerId())
          ->cachePerPermissions()
          ->cachePerUser()
          ->cacheUntilEntityChanges($log);
      }
    case 'delete':
      if ($account
        ->hasPermission('delete any ' . $type . ' log entities', $account)) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      else {
        return AccessResult::allowedIf($account
          ->hasPermission('delete own ' . $type . ' log entities', $account) && $account
          ->id() == $log
          ->getOwnerId())
          ->cachePerPermissions()
          ->cachePerUser()
          ->cacheUntilEntityChanges($log);
      }
    default:

      // No opinion.
      return AccessResult::neutral();
  }
}