1); } } /** * Define default file types. * * File types are implemented as CTools exportables, so modules can alter the * defaults via hook_file_default_types_alter(), and the administrator can * save overridden and custom types to the {file_type} database table. * * @return array * An array whose keys are file type names and whose values are objects * representing the file type, with the following key/value pairs: * - api_version: The version of this data. * - type: The file type name. * - label: The human-readable name of the file type. * - description: The description of this file type. * - mimetypes: An array of mimetypes that this file type will map to. */ function hook_file_default_types() { return array( 'image' => (object) array( 'api_version' => 1, 'type' => 'image', 'label' => t('Image'), 'description' => t("An Image is a two-dimensional picture that has a similar appearance to some subject, usually a physical object or a person."), 'mimetypes' => array( 'image/*', ), ), ); } /** * Alter default file types. * * @see hook_file_default_types() */ function hook_file_default_types_alter(&$types) { $types['image']->mimetypes[] = 'image/svg+xml'; } /** * Define file formatters. * * @return array * An array whose keys are file formatter names and whose values are arrays * describing the formatter. * * @todo Document key/value pairs that comprise a formatter. * * @see hook_file_formatter_info_alter() */ function hook_file_formatter_info() { // @todo Add example. } /** * Perform alterations on file formatters. * * @param array $info * Array of information on file formatters exposed by * hook_file_formatter_info() implementations. */ function hook_file_formatter_info_alter(&$info) { // @todo Add example. } /** * @todo Add documentation. * * Note: This is not really a hook. The function name is manually specified via * 'view callback' in hook_file_formatter_info(), with this recommended callback * name pattern. */ function hook_file_formatter_FORMATTER_view($file, $display, $langcode) { } /** * @todo Add documentation. * * Note: This is not really a hook. The function name is manually specified via * 'settings callback' in hook_file_formatter_info(), with this recommended * callback name pattern. */ function hook_file_formatter_FORMATTER_settings($form, &$form_state, $settings) { } /** * @todo Add documentation. */ function hook_file_displays_alter($displays, $file, $view_mode) { } /** * @todo Add documentation. */ function hook_file_view($file, $view_mode, $langcode) { } /** * @todo Add documentation. */ function hook_file_view_alter($build, $type) { } /** * Add mass file operations. * * This hook enables modules to inject custom operations into the mass * operations dropdown found at admin/content/file, by associating a callback * function with the operation, which is called when the form is submitted. The * callback function receives one initial argument, which is an array of the * checked files. * * @return array * An array of operations. Each operation is an associative array that may * contain the following key-value pairs: * - 'label': Required. The label for the operation, displayed in the dropdown * menu. * - 'callback': Required. The function to call for the operation. * - 'callback arguments': Optional. An array of additional arguments to pass * to the callback function. */ function hook_file_operations() { $operations = array( 'delete' => array( 'label' => t('Delete selected files'), 'callback' => NULL, ), ); return $operations; } /** * 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. * * @param string $op * The operation to be performed. Possible values: * - "create" * - "delete" * - "update" * - "view" * - "download" * @param 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. * @param object $account * A user object representing the user for whom the operation is to be * performed. * * @return 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. * * @ingroup file_entity_access */ 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; } /** * 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, '<='); } /** * Act on a file being displayed as a search result. * * This hook is invoked from file_entity_search_execute(), after file_load() * and file_view() have been called. * * @param object $file * The file being displayed in a search result. * * @return array * Extra information to be displayed with search result. This information * should be presented as an associative array. It will be concatenated * with the file information (filename) in the default search result theming. * * @see template_preprocess_search_result() * @see search-result.tpl.php * * @ingroup file_entity_api_hooks */ function hook_file_entity_search_result($file) { $file_usage_count = db_query('SELECT count FROM {file_usage} WHERE fid = :fid', array('fid' => $file->fid))->fetchField(); return array( 'file_usage_count' => format_plural($file_usage_count, '1 use', '@count uses'), ); } /** * Act on a file being indexed for searching. * * This hook is invoked during search indexing, after file_load(), and after * the result of file_view() is added as $file->rendered to the file object. * * @param object $file * The file being indexed. * * @return string * Additional file information to be indexed. * * @ingroup file_entity_api_hooks */ function hook_file_update_index($file) { $text = ''; $uses = db_query('SELECT module, count FROM {file_usage} WHERE fid = :fid', array(':fid' => $file->fid)); foreach ($uses as $use) { $text .= '