You are here

function farm_asset_farm_asset_view_page in farmOS 7

Entry point for our overridden farm_asset view.

This function asks its assigned handlers who, if anyone, would like to run with it. If no one does, it passes through to Drupal core's farm_asset view, which is farm_asset_view().

Parameters

FarmAsset $farm_asset: The farm asset entity.

Return value

array Returns a render array.

1 string reference to 'farm_asset_farm_asset_view_page'
farm_asset_farm_asset_view_menu_alter in modules/farm/farm_asset/includes/ctools/farm_asset_view.inc
Callback defined by farm_asset_farm_asset_view_farm_asset_tasks().

File

modules/farm/farm_asset/includes/ctools/farm_asset_view.inc, line 93
Handle the 'farm_asset view' override task.

Code

function farm_asset_farm_asset_view_page(FarmAsset $farm_asset) {

  // Load farm_asset task plugin.
  $task = page_manager_get_task('farm_asset_view');

  // Load the farm_asset into a context.
  ctools_include('context');
  ctools_include('context-task-handler');

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

  // Set the farm_asset 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(
    $farm_asset,
  ));
  $output = ctools_context_handler_render($task, '', $contexts, array(
    $farm_asset->id,
  ));
  if ($output != FALSE) {
    return $output;
  }
  module_load_include('inc', 'farm_asset', 'farm_asset.pages');
  $function = 'farm_asset_view';
  foreach (module_implements('farm_asset_override') as $module) {
    $call = $module . '_farm_asset_override';
    if (($rc = $call('farm_asset_view')) && function_exists($rc)) {
      $function = $rc;
      break;
    }
  }

  // Otherwise, fall back.
  return $function($farm_asset);
}