You are here

function file_entity_file_view_page in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 7.2 plugins/tasks/file_view.inc \file_entity_file_view_page()

Entry point for our overridden file view.

This function asks its assigned handlers who, if anyone, would like to run with it. If no one does, it passes through to File entity's file view, which is file_entity_view_page().

1 string reference to 'file_entity_file_view_page'
file_entity_file_view_menu_alter in plugins/tasks/file_view.inc
Callback defined by page_manager_file_view_page_manager_tasks().

File

plugins/tasks/file_view.inc, line 75
Handle the 'file view' override task.

Code

function file_entity_file_view_page($file) {

  // Load my task plugin:
  $task = page_manager_get_task('file_view');

  // Load the account into a context.
  ctools_include('context');
  ctools_include('context-task-handler');
  $contexts = ctools_context_handler_get_task_contexts($task, '', array(
    $file,
  ));

  // We need to mimic Drupal's behavior of setting the file title here.
  drupal_set_title($file->filename);
  $uri = entity_uri('file', $file);

  // Set the file path as the canonical URL to prevent duplicate content.
  drupal_add_html_head_link(array(
    'rel' => 'canonical',
    'href' => url($uri['path'], $uri['options']),
  ), TRUE);

  // Set the non-aliased path as a default shortlink.
  drupal_add_html_head_link(array(
    'rel' => 'shortlink',
    'href' => url($uri['path'], array_merge($uri['options'], array(
      'alias' => TRUE,
    ))),
  ), TRUE);
  $contexts = ctools_context_handler_get_task_contexts($task, '', array(
    $file,
  ));
  $output = ctools_context_handler_render($task, '', $contexts, array(
    $file->fid,
  ));
  if ($output != FALSE) {
    return $output;
  }
  $function = 'file_entity_view_page';
  foreach (module_implements('page_manager_override') as $module) {
    $call = $module . '_page_manager_override';
    if (($rc = $call('file_view')) && function_exists($rc)) {
      $function = $rc;
      break;
    }
  }

  // Otherwise, fall back.
  module_load_include('inc', 'file_entity', 'file_entity.pages');
  return $function($file);
}