function hook_file_entity_access in File Entity (fieldable files) 7.3
Same name and namespace in other branches
- 7.2 file_entity.api.php \hook_file_entity_access()
Control access to a file.
Modules may implement this hook if they want to have a say in whether or not a given user has access to perform a given operation on a file.
The administrative account (user ID #1) always passes any access check, so this hook is not called in that case. Users with the "bypass file access" permission may always view and edit files through the administrative interface.
Note that not all modules will want to influence access on all file types. If your module does not want to actively grant or block access, return FILE_ENTITY_ACCESS_IGNORE or simply return nothing. Blindly returning FALSE will break other file access modules.
Parameters
string $op: The operation to be performed. Possible values:
- "create"
- "delete"
- "update"
- "view"
- "download".
object $file: The file on which the operation is to be performed, or, if it does not yet exist, the type of file to be created.
object $account: A user object representing the user for whom the operation is to be performed.
Return value
string|null FILE_ENTITY_ACCESS_ALLOW if the operation is to be allowed; FILE_ENTITY_ACCESS_DENY if the operation is to be denied; FILE_ENTITY_ACCESS_IGNORE to not affect this operation at all.
Related topics
1 function implements hook_file_entity_access()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- file_entity_file_entity_access in ./
file_entity.module - Implements hook_file_entity_access().
1 invocation of hook_file_entity_access()
- file_entity_access in ./
file_entity.module - Determine if a user may perform the given operation on the specified file.
File
- ./
file_entity.api.php, line 188 - Hooks provided by the File Entity module.
Code
function hook_file_entity_access($op, $file, $account) {
$type = is_string($file) ? $file : $file->type;
if ($op !== 'create' && REQUEST_TIME - $file->timestamp < 3600) {
// If the file was uploaded in the last hour, deny access to it.
return FILE_ENTITY_ACCESS_DENY;
}
// Returning nothing from this function would have the same effect.
return FILE_ENTITY_ACCESS_IGNORE;
}