CacheflushEntityAccessControlHandler.php in CacheFlush 8
File
modules/cacheflush_ui/src/CacheflushEntityAccessControlHandler.php
View source
<?php
namespace Drupal\cacheflush_ui;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
class CacheflushEntityAccessControlHandler extends EntityAccessControlHandler {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'clear':
return $this
->checkSingleToMany('cacheflush clear any', 'cacheflush clear own', $account, $entity);
case 'view':
return $this
->checkSingleToMany('cacheflush view any', 'cacheflush view own', $account, $entity);
case 'update':
return $this
->checkSingleToMany('cacheflush edit any', 'cacheflush edit own', $account, $entity);
case 'delete':
return $this
->checkSingleToMany('cacheflush delete any', 'cacheflush delete own', $account, $entity);
}
return AccessResult::allowed();
}
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'cacheflush create new');
}
protected function checkSingleToMany($any, $single, $account, $entity) {
return AccessResult::allowedIfHasPermission($account, $any)
->orIf(AccessResult::allowedIfHasPermission($account, $single)
->andIf($this
->checkOwner($account, $entity)));
}
protected function checkOwner($account, $entity) {
if ($account
->id() == $entity
->getOwnerId()) {
return AccessResult::allowed();
}
return AccessResult::neutral();
}
}