1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Display Suite Extras page functions.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Menu callback: show an individual node with the Switch field.
|
10
|
*/
|
11
|
function ds_extras_node_page_view($node) {
|
12
|
|
13
|
// If there is a menu link to this node, the link becomes the last part
|
14
|
// of the active trail, and the link name becomes the page title.
|
15
|
// Thus, we must explicitly set the page title to be the node title.
|
16
|
drupal_set_title($node->title);
|
17
|
$uri = entity_uri('node', $node);
|
18
|
// Set the node path as the canonical URL to prevent duplicate content.
|
19
|
drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);
|
20
|
// Set the non-aliased path as a default shortlink.
|
21
|
drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE);
|
22
|
|
23
|
// Update the history table, stating that this user viewed this node.
|
24
|
node_tag_new($node);
|
25
|
|
26
|
if (empty($node->ds_switch)) {
|
27
|
// When not set fall back to full
|
28
|
$view_mode = 'full';
|
29
|
}
|
30
|
elseif ($node->ds_switch == 'default') {
|
31
|
// When default set fall back to full
|
32
|
$view_mode = 'full';
|
33
|
}
|
34
|
else {
|
35
|
$view_mode = $node->ds_switch;
|
36
|
}
|
37
|
|
38
|
// It's also possible to use $_GET['v'] to switch view modes.
|
39
|
if (isset($_GET['v']) && !empty($_GET['v'])) {
|
40
|
$view_mode = $_GET['v'];
|
41
|
// Check if this is a valid view mode, switch to default otherwise.
|
42
|
$view_modes = ds_extras_get_bundle_view_modes('node', $node->type);
|
43
|
if (!isset($view_modes[$view_mode])) {
|
44
|
$view_mode = 'full';
|
45
|
}
|
46
|
}
|
47
|
drupal_static('ds_extras_view_mode', $view_mode);
|
48
|
|
49
|
// For markup consistency with other pages, use node_view_multiple() rather than node_view().
|
50
|
return node_view_multiple(array($node->nid => $node), $view_mode);
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Menu callback: switches to another view mode inline.
|
55
|
*/
|
56
|
function ds_switch_view_mode_inline() {
|
57
|
|
58
|
$content = '';
|
59
|
$status = TRUE;
|
60
|
$error = FALSE;
|
61
|
|
62
|
$id = $_REQUEST['id'];
|
63
|
$view_mode = $_REQUEST['view_mode'];
|
64
|
$entity_type = $_REQUEST['entity_type'];
|
65
|
$entity = entity_load($entity_type, array($id));
|
66
|
|
67
|
if (!isset($entity[$id])) {
|
68
|
$status = FALSE;
|
69
|
$error = t('Content was not found.');
|
70
|
}
|
71
|
else {
|
72
|
if (node_access('view', $entity[$id])) {
|
73
|
$element = node_view($entity[$id], $view_mode);
|
74
|
$content = drupal_render($element);
|
75
|
}
|
76
|
else {
|
77
|
$error = t('Access denied');
|
78
|
}
|
79
|
}
|
80
|
|
81
|
drupal_add_http_header('Content-Type', 'text/javascript; charset=utf-8');
|
82
|
print drupal_json_encode(array(
|
83
|
'status' => $status,
|
84
|
'content' => $content,
|
85
|
'errorMessage' => $error,
|
86
|
));
|
87
|
exit();
|
88
|
}
|