label() == 'forbid_access') { return AccessResult::forbidden(); } if ($operation === 'view label' && $entity instanceof EntityTestLabel) { // Viewing the label of the 'entity_test_label' entity type is allowed. return AccessResult::allowed(); } elseif (in_array($operation, ['view', 'view label'])) { if (!$entity->isDefaultTranslation()) { return AccessResult::allowedIfHasPermission($account, 'view test entity translations'); } return AccessResult::allowedIfHasPermission($account, 'view test entity'); } elseif (in_array($operation, ['update', 'delete'])) { return AccessResult::allowedIfHasPermission($account, 'administer entity_test content'); } // No opinion. return AccessResult::neutral(); } /** * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { return AccessResult::allowedIfHasPermissions($account, [ 'administer entity_test content', 'administer entity_test_with_bundle content', 'create ' . $entity_bundle . ' entity_test_with_bundle entities', ], 'OR'); } }