You are here

function file_view in File Entity (fieldable files) 7

Same name and namespace in other branches
  1. 7.3 file_entity.file_api.inc \file_view()
  2. 7.2 file_entity.file_api.inc \file_view()

Generate an array for rendering the given file.

Parameters

$file: A file object.

$view_mode: View mode.

$langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.

Return value

An array as expected by drupal_render().

6 calls to file_view()
file_entity_test_edit_form in tests/file_entity_test.pages.inc
Form callback; edit a file.
file_entity_test_preview_page in tests/file_entity_test.pages.inc
Page callback; preview a file.
file_entity_test_view_page in tests/file_entity_test.pages.inc
Page callback; view a file.
file_entity_view_page in ./file_entity.pages.inc
Menu callback; view a single file entity.
file_view_multiple in ./file_entity.file_api.inc
Construct a drupal_render() style array from an array of loaded files.

... See full list

File

./file_entity.file_api.inc, line 141
API extensions of Drupal core's file.inc.

Code

function file_view($file, $view_mode = 'full', $langcode = NULL) {
  if (!isset($langcode)) {
    $langcode = $GLOBALS['language_content']->language;
  }

  // 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';
  drupal_alter(array(
    'file_view',
    'entity_view',
  ), $build, $type);
  return $build;
}