protected function PathFileEntityAccessControlHandler::checkAccess in Path File 8
Performs access checks.
This method is supposed to be overwritten by extending classes that do their own custom access checking.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.
string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.
\Drupal\Core\Session\AccountInterface $account: The user for which to check access.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
Overrides EntityAccessControlHandler::checkAccess
File
- src/
PathFileEntityAccessControlHandler.php, line 20
Class
- PathFileEntityAccessControlHandler
- Access controller for the Path file entity entity.
Namespace
Drupal\path_fileCode
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
// @var \Drupal\path_file\Entity\PathFileEntityInterface $entity
// Default to Unknown operation, no opinion.
$access_result = AccessResult::neutral();
switch ($operation) {
case 'view':
if (!$entity
->isPublished()) {
$access_result = AccessResult::allowedIfHasPermission($account, 'view unpublished path file entity entities');
}
else {
$access_result = AccessResult::allowedIfHasPermission($account, 'view published path file entity entities');
}
break;
case 'update':
$access_result = AccessResult::allowedIfHasPermission($account, 'edit path file entity entities');
break;
case 'delete':
$access_result = AccessResult::allowedIfHasPermission($account, 'delete path file entity entities');
break;
}
// Add Cache contexts.
$access_result
->cachePerPermissions();
$access_result
->addCacheableDependency($entity);
return $access_result;
}