1.20.x file.module | file_view($file, $view_mode = 'full', $langcode = NULL) |
Generate an array for rendering the given file.
Parameters
object $file: A file object.
string $view_mode: View mode.
string $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.
Return value
array: An array as expected by backdrop_render().
File
- modules/
file/ file.module, line 3295 - Defines a "managed_file" Form API field and a "file" field for Field module.
Code
function file_view($file, $view_mode = 'full', $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->langcode;
}
// Populate $file->content with a render() array.
file_build_content($file, $view_mode, $langcode);
$build = $file->content;
// We don't need duplicate rendering info in $file->content.
unset($file->content);
$build += array(
'#theme' => 'file_entity',
'#file' => $file,
'#view_mode' => $view_mode,
'#language' => $langcode,
);
// Add contextual links for this file, except when the file is already being
// displayed on its own page. Modules may alter this behavior (for example,
// to restrict contextual links to certain view modes) by implementing
// hook_file_view_alter().
if (!empty($file->fid) && !($view_mode == 'full' && file_is_page($file))) {
$build['#contextual_links']['file'] = array('file', array($file->fid));
}
// Allow modules to modify the structured file.
$type = 'file';
backdrop_alter(array('file_view', 'entity_view'), $build, $type);
return $build;
}