You are here

function video_file_access in Video 8.2

Same name and namespace in other branches
  1. 8 video.module \video_file_access()

Implements hook_ENTITY_TYPE_access().

File

./video.module, line 27
Exposes global functionality for video fields.

Code

function video_file_access(EntityInterface $entity, $operation, AccountInterface $account) {
  switch ($operation) {
    case 'view':

      /** @var \Drupal\video\ProviderManager $provider_manager */
      $provider_manager = \Drupal::service('video.provider_manager');
      $stream_wrappers = [];
      foreach ($provider_manager
        ->getDefinitions() as $definition) {
        $stream_wrappers[] = $definition['id'];
      }
      $file_entity = File::load($entity
        ->id());
      $scheme = \Drupal::service('stream_wrapper_manager')
        ->getScheme($file_entity
        ->getFileUri());
      if (in_array($scheme, $stream_wrappers)) {
        return AccessResult::allowedIfHasPermission($account, 'access content');
      }
      return AccessResult::neutral();
    default:
      return AccessResult::neutral();
  }
}