You are here

function file_view in D7 Media 7

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().

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

File

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

Code

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

  // Prepare the file object for viewing, in case file_view() was called by
  // something other than file_view_multiple(). These functions exit quickly if
  // they've already run, so it's okay to call them even if they've already been
  // called by file_view_multiple().
  field_attach_prepare_view('file', array(
    $file->fid => $file,
  ), $view_mode);
  entity_prepare_view('file', array(
    $file->fid => $file,
  ));

  // Create the render array with the file itself and with fields.
  $build = array(
    '#file' => $file,
    '#view_mode' => $view_mode,
    '#language' => $langcode,
  );
  $build += field_attach_view('file', $file, $view_mode, $langcode);
  $build['file'] = file_view_file($file, $view_mode, $langcode);

  // Allow modules to add and alter.
  module_invoke_all('file_view', $file, $view_mode, $langcode);
  module_invoke_all('entity_view', $file, 'file', $view_mode, $langcode);
  $type = 'file';
  drupal_alter(array(
    'file_view',
    'entity_view',
  ), $build, $type);
  return $build;
}