-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfoxml.module
40 lines (35 loc) · 1.03 KB
/
foxml.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* @file
* General hook implementations.
*/
/**
* Implements hook_file_download().
*/
function foxml_file_download(string $uri) {
/** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
$scheme = $stream_wrapper_manager->getScheme($uri);
if (!in_array($scheme, ['foxml', 'foxml.substream'])) {
return NULL;
}
/** @var \Drupal\file\FileRepositoryInterface $file_repository */
$file_repository = \Drupal::service('file.repository');
$file = $file_repository->loadByUri($uri);
if (!$file) {
// Failed to load file entity, only grant access if the lower-level
// permission is present.
$user = \Drupal::currentUser();
return $user->hasPermission('access referenced foxml') ?
[
'Cache-Control' => 'private',
] :
-1;
}
else {
$file_name = $file->getFileName();
return [
'Content-Disposition' => 'attachment; filename="' . $file_name . '"',
];
}
}