1 file.module file_build_content($file, $view_mode = 'full', $langcode = NULL)

Builds a structured array representing the file's content.

Parameters

object $file: A file object.

string $view_mode: View mode, e.g. 'default', 'full', etc.

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

File

core/modules/file/file.module, line 3302
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

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

  // Remove previously built content, if exists.
  $file->content = array();

  // In case of a multiple view, file_view_multiple() already ran the
  // 'prepare_view' step. An internal flag prevents the operation from running
  // twice.
  // Allow modules to change the view mode.
  $view_mode = key(entity_view_mode_prepare('file', array($file->fid => $file), $view_mode, $langcode));
  field_attach_prepare_view('file', array($file->fid => $file), $view_mode, $langcode);
  entity_prepare_view('file', array($file->fid => $file), $langcode);

  // Build the actual file display.
  // @todo Figure out how to clean this crap up.
  $file->content['file'] = file_view_file($file, $view_mode, $langcode);
  if (isset($file->content['file'])) {
    if (isset($file->content['file']['#theme']) && $file->content['file']['#theme'] != 'file_link') {
      unset($file->content['file']['#file']);
    }
    unset($file->content['file']['#view_mode']);
    unset($file->content['file']['#language']);
  }
  else {
    unset($file->content['file']);
  }

  // Build fields content.
  $file->content += field_attach_view('file', $file, $view_mode, $langcode);

  $links = array();
  $file->content['links'] = array(
    '#theme' => 'links__file',
    '#pre_render' => array('backdrop_pre_render_links'),
    '#attributes' => array('class' => array('links', 'inline')),
  );
  $file->content['links']['file'] = array(
    '#theme' => 'links__file__file',
    '#links' => $links,
    '#attributes' => array('class' => array('links', 'inline')),
  );

  // Allow modules to make their own additions to the file.
  module_invoke_all('file_view', $file, $view_mode, $langcode);
  module_invoke_all('entity_view', $file, 'file', $view_mode, $langcode);
}