3 namespace Drupal\entity;
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityAccessControlHandler as CoreEntityAccessControlHandler;
7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Session\AccountInterface;
11 * Controls access to bundle entities.
13 * Allows the bundle entity label to be viewed if the account has
14 * access to view entities of that bundle.
16 class BundleEntityAccessControlHandler extends CoreEntityAccessControlHandler {
21 protected $viewLabelOperation = TRUE;
26 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
27 if ($operation === 'view label') {
28 $bundle = $entity->id();
29 $entity_type_id = $this->entityType->getBundleOf();
31 "administer $entity_type_id",
32 // View permissions provided by EntityPermissionProvider.
33 "view $entity_type_id",
34 "view $bundle $entity_type_id",
35 // View permissions provided by UncacheableEntityPermissionProvider.
36 "view own $entity_type_id",
37 "view any $entity_type_id",
38 "view own $bundle $entity_type_id",
39 "view any $bundle $entity_type_id",
42 return AccessResult::allowedIfHasPermissions($account, $permissions, 'OR');
45 return parent::checkAccess($entity, $operation, $account);