Check access to entity for logged in user in Drupal 8 I have added private message module for one of my project which has it's own entity. I need to check whether the user is having access to that entity content or not. The module has it's menu item defined in the module's routing.yml 

e.g.:

entity.private_message_thread.canonical:
  path: '/private_messages/{private_message_thread}'
  defaults:
    _entity_view: 'private_message_thread'
    _title: 'Private Messages'
  requirements:
    _entity_access: 'private_message_thread.view'


How could I check whether the user has view access to the above menu path?
You can check annotations of those entities and find access handler.

e.g. 

/**
 * Defines the Private Message Thread entity.
 *
 * @ContentEntityType(
 *   id = "private_message_thread",
 *   label = @Translation("Private Message Thread"),
 *   handlers = {
 *     "view_builder" = "Drupal\private_message\Entity\Builder\PrivateMessageThreadViewBuilder",
 *     "views_data" = "Drupal\views\EntityViewsData",
 *     "access" = "Drupal\private_message\Entity\Access\PrivateMessageThreadAccessControlHandler",
 ...


As you can see, there is access handler. Now you know how it works.

  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    if ($account-&gt;hasPermission('use private messaging system')) {
      switch ($operation) {
        case 'view':
          if ($entity-&gt;isMember($account-&gt;id())) {
            $messages = $entity-&gt;filterUserDeletedMessages($account);
            if (count($messages)) {
              return AccessResult::allowed();
            }
          }
          ...