- Issue created by @drupgirl
- 🇮🇳India arunkumark Coimbatore
@drupgirl
If you want hide file access always, simply use below hook and Access controller,
/** * Implements hook_entity_type_alter(). */ function your_module_entity_type_alter(&$entity_types) { $entity_types['file']->setAccessClass('Drupal\your_module\FileViewAccessControlHandler'); }
Access handler path: your_module/src/FileViewAccessControlHandler.php
<?php namespace Drupal\your_module; use Drupal\Core\Access\AccessResult; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\file\FileAccessFormatterControlHandlerInterface; use Drupal\file\FileAccessControlHandler; /** * Provides a File access control handler. */ class FileViewAccessControlHandler extends FileAccessControlHandler implements FileAccessFormatterControlHandlerInterface { /** * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { // Check if the file permission exists or not. if ($operation == 'view') { return AccessResult::forbidden(); } // For other operations, fall back to the parent check. return parent::checkAccess($entity, $operation, $account); } }