function video_file_access in Video 8
Same name and namespace in other branches
- 8.2 video.module \video_file_access()
Implements hook_ENTITY_TYPE_access().
File
- ./
video.module, line 26 - 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'];
}
$scheme = \Drupal::service('file_system')
->uriScheme($entity
->getFileUri());
if (in_array($scheme, $stream_wrappers)) {
return AccessResult::allowedIfHasPermission($account, 'access content');
}
return AccessResult::neutral();
default:
return AccessResult::neutral();
}
}