site_audit-8.x-3.0-rc1/site_audit_report_entity/src/SiteAuditReportAccessControlHandler.php
site_audit_report_entity/src/SiteAuditReportAccessControlHandler.php
<?php
namespace Drupal\site_audit_report_entity;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Defines the access control handler for the site audit report entity type.
*/
class SiteAuditReportAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view site audit report');
case 'update':
return AccessResult::allowedIfHasPermissions(
$account,
['edit site audit report', 'administer site audit report'],
'OR',
);
case 'delete':
return AccessResult::allowedIfHasPermissions(
$account,
['delete site audit report', 'administer site audit report'],
'OR',
);
default:
// No opinion.
return AccessResult::neutral();
}
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermissions(
$account,
['create site audit report', 'administer site audit report'],
'OR',
);
}
}
