EntityTestAccessControlHandler.php in Zircon Profile 8
File
core/modules/system/tests/modules/entity_test/src/EntityTestAccessControlHandler.php
View source
<?php
namespace Drupal\entity_test;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Session\AccountInterface;
class EntityTestAccessControlHandler extends EntityAccessControlHandler {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
if ($entity
->label() == 'forbid_access') {
return AccessResult::forbidden();
}
if ($operation === 'view') {
if (!$entity
->isDefaultTranslation()) {
return AccessResult::allowedIfHasPermission($account, 'view test entity translations');
}
return AccessResult::allowedIfHasPermission($account, 'view test entity');
}
elseif (in_array($operation, array(
'update',
'delete',
))) {
return AccessResult::allowedIfHasPermission($account, 'administer entity_test content');
}
return AccessResult::neutral();
}
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'administer entity_test content');
}
}