You are here

protected function FileFormatterBase::checkAccess in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase::checkAccess()

Checks access to the given entity.

By default, entity 'view' access is checked. However, a subclass can choose to exclude certain items from entity access checking by immediately granting access.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to check.

Return value

\Drupal\Core\Access\AccessResult A cacheable access result.

Overrides EntityReferenceFormatterBase::checkAccess

File

core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php, line 25

Class

FileFormatterBase
Base class for file formatters.

Namespace

Drupal\file\Plugin\Field\FieldFormatter

Code

protected function checkAccess(EntityInterface $entity) {

  // Only check access if the current file access control handler explicitly
  // opts in by implementing FileAccessFormatterControlHandlerInterface.
  $access_handler_class = $entity
    ->getEntityType()
    ->getHandlerClass('access');
  if (is_subclass_of($access_handler_class, '\\Drupal\\file\\FileAccessFormatterControlHandlerInterface')) {
    return $entity
      ->access('view', NULL, TRUE);
  }
  else {
    return AccessResult::allowed();
  }
}