You are here

function ds_extras_node_page_view in Display Suite 7.2

Same name and namespace in other branches
  1. 7 modules/ds_extras/ds_extras.pages.inc \ds_extras_node_page_view()

Menu callback: show an individual node with the Switch field.

1 string reference to 'ds_extras_node_page_view'
_ds_extras_menu_alter in modules/ds_extras/includes/ds_extras.registry.inc
Implements hook_menu_alter().

File

modules/ds_extras/includes/ds_extras.pages.inc, line 11
Display Suite Extras page functions.

Code

function ds_extras_node_page_view($node) {

  // If there is a menu link to this node, the link becomes the last part
  // of the active trail, and the link name becomes the page title.
  // Thus, we must explicitly set the page title to be the node title.
  drupal_set_title($node->title);
  $uri = entity_uri('node', $node);

  // Set the node 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);

  // Update the history table, stating that this user viewed this node.
  node_tag_new($node);
  if (empty($node->ds_switch)) {

    // When not set fall back to full
    $view_mode = 'full';
  }
  elseif ($node->ds_switch == 'default') {

    // When default set fall back to full
    $view_mode = 'full';
  }
  else {
    $view_mode = $node->ds_switch;
  }

  // It's also possible to use $_GET['v'] to switch view modes.
  if (isset($_GET['v']) && !empty($_GET['v'])) {
    $view_mode = $_GET['v'];

    // Check if this is a valid view mode, switch to default otherwise.
    $view_modes = ds_extras_get_bundle_view_modes('node', $node->type);
    if (!isset($view_modes[$view_mode])) {
      $view_mode = 'full';
    }
  }
  drupal_static('ds_extras_view_mode', $view_mode);

  // For markup consistency with other pages, use node_view_multiple() rather than node_view().
  return node_view_multiple(array(
    $node->nid => $node,
  ), $view_mode);
}