1 file.api.php hook_file_search_result($file)

Act on a file being displayed as a search result.

This hook is invoked from file_search_execute(), after file_load() and file_view() have been called.

Parameters

object $file: The file being displayed in a search result.

Return value

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 also

template_preprocess_search_result()

search-result.tpl.php

File

core/modules/file/file.api.php, line 305
Hooks for file module.

Code

function hook_file_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'),
  );
}