This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
file_entity.api.php
103 lines (93 loc) · 2.31 KB
/
file_entity.api.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @file
* Hooks provided by the File Entity module.
*/
/**
* Control access to listings of files.
*
* @param object $query
* A query object describing the composite parts of a SQL query related to
* listing files.
*
* @see hook_query_TAG_alter()
* @ingroup file_entity_access
*/
function hook_query_file_entity_access_alter(QueryAlterableInterface $query) {
// Only show files that have been uploaded more than an hour ago.
$query->condition('timestamp', REQUEST_TIME - 3600, '<=');
}
/**
* Alter file download headers.
*
* @param array $headers
* Array of download headers.
* @param object $file
* File object.
*/
function hook_file_download_headers_alter(array &$headers, $file) {
// Instead of being powered by PHP, tell the world this resource was powered
// by your custom module!
$headers['X-Powered-By'] = 'My Module';
}
/**
* React to a file being downloaded.
*/
function hook_file_transfer($uri, array $headers) {
// Redirect a download for an S3 file to the actual location.
if (file_uri_scheme($uri) == 's3') {
$url = file_create_url($uri);
drupal_goto($url);
}
}
/**
* Decides which file type (bundle) should be assigned to a file entity.
*
* @param object $file
* File object.
*
* @return array
* Array of file type machine names that can be assigned to a given file type.
* If there are more proposed file types the one, that was returned the first,
* wil be chosen. This can be, however, changed in alter hook.
*
* @see hook_file_type_alter()
*/
function hook_file_type($file) {
// Assign all files uploaded by anonymous users to a special file type.
if (user_is_anonymous()) {
return array('untrusted_files');
}
}
/**
* Alters list of file types that can be assigned to a file.
*
* @param array $types
* List of proposed types.
* @param object $file
* File object.
*/
function hook_file_type_alter(&$types, $file) {
// Choose a specific, non-first, file type.
$types = array($types[4]);
}
/**
* Provides metadata information.
*
* @todo Add documentation.
*
* @return array
* An array of metadata information.
*/
function hook_file_metadata_info() {
}
/**
* Alters metadata information.
*
* @todo Add documentation.
*
* @return array
* an array of metadata information.
*/
function hook_file_metadata_info_alter() {
}