function FileFormatterBase::checkAccess

Same name in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase::checkAccess()
  2. 10 core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase::checkAccess()
  3. 11.x core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase::checkAccess()

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();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.