Projet

Général

Profil

Paste
Télécharger (5,79 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / page_manager / plugins / tasks / node_view.inc @ 651307cd

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Handle the 'node view' override task.
6
 *
7
 * This plugin overrides node/%node and reroutes it to the page manager, where
8
 * a list of tasks can be used to service this request based upon criteria
9
 * supplied by access plugins.
10
 */
11
12
/**
13
 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
14
 * more information.
15
 */
16
function page_manager_node_view_page_manager_tasks() {
17
  return array(
18
    // This is a 'page' task and will fall under the page admin UI
19
    'task type' => 'page',
20
21
    'title' => t('Node template'),
22
23
    'admin title' => t('Node template'),
24
    'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying nodes at <em>node/%node</em>. If you add variants, you may use selection criteria such as node type or language or user access to provide different views of nodes. If no variant is selected, the default Drupal node view will be used. This page only affects nodes viewed as pages, it will not affect nodes viewed in lists or at other locations. Also please note that if you are using pathauto, aliases may make a node to be somewhere else, but as far as Drupal is concerned, they are still at node/%node.'),
25
    'admin path' => 'node/%node',
26
27
    // Menu hooks so that we can alter the node/%node menu entry to point to us.
28
    'hook menu' => 'page_manager_node_view_menu',
29
    'hook menu alter' => 'page_manager_node_view_menu_alter',
30
31
    // This is task uses 'context' handlers and must implement these to give the
32
    // handler data it needs.
33
    'handler type' => 'context',
34
    'get arguments' => 'page_manager_node_view_get_arguments',
35
    'get context placeholders' => 'page_manager_node_view_get_contexts',
36
37
    // Allow this to be enabled or disabled:
38
    'disabled' => variable_get('page_manager_node_view_disabled', TRUE),
39
    'enable callback' => 'page_manager_node_view_enable',
40
    'access callback' => 'page_manager_node_view_access_check',
41
  );
42
}
43
44
/**
45
 * Callback defined by page_manager_node_view_page_manager_tasks().
46
 *
47
 * Alter the node view input so that node view comes to us rather than the
48
 * normal node view process.
49
 */
50
function page_manager_node_view_menu_alter(&$items, $task) {
51
  if (variable_get('page_manager_node_view_disabled', TRUE)) {
52
    return;
53
  }
54
55
  // Override the node view handler for our purpose.
56
  $callback = $items['node/%node']['page callback'];
57
  if ($callback == 'node_page_view' || variable_get('page_manager_override_anyway', FALSE)) {
58
    $items['node/%node']['page callback'] = 'page_manager_node_view_page';
59
    $items['node/%node']['file path'] = $task['path'];
60
    $items['node/%node']['file'] = $task['file'];
61
  }
62
  else {
63
    // automatically disable this task if it cannot be enabled.
64
    variable_set('page_manager_node_view_disabled', TRUE);
65
    if (!empty($GLOBALS['page_manager_enabling_node_view'])) {
66
      drupal_set_message(t('Page manager module is unable to enable node/%node because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
67
    }
68
  }
69
70
  // @todo override node revision handler as well?
71
}
72
73
/**
74
 * Entry point for our overridden node view.
75
 *
76
 * This function asks its assigned handlers who, if anyone, would like
77
 * to run with it. If no one does, it passes through to Drupal core's
78
 * node view, which is node_page_view().
79
 */
80
function page_manager_node_view_page($node) {
81
  // Load my task plugin
82
  $task = page_manager_get_task('node_view');
83
84
  // Load the node into a context.
85
  ctools_include('context');
86
  ctools_include('context-task-handler');
87
88 e4c061ad Assos Assos
  // Load all contexts.
89 85ad3d82 Assos Assos
  $contexts = ctools_context_handler_get_task_contexts($task, '', array($node));
90
91 e4c061ad Assos Assos
  // Build the full output using the configured CTools plugin.
92 85ad3d82 Assos Assos
  $output = ctools_context_handler_render($task, '', $contexts, array($node->nid));
93 e4c061ad Assos Assos
  if ($output !== FALSE) {
94 85ad3d82 Assos Assos
    node_tag_new($node);
95
    return $output;
96
  }
97
98 e4c061ad Assos Assos
  // Try loading an override plugin.
99 85ad3d82 Assos Assos
  foreach (module_implements('page_manager_override') as $module) {
100
    $call = $module . '_page_manager_override';
101
    if (($rc = $call('node_view')) && function_exists($rc)) {
102 e4c061ad Assos Assos
      return $rc($node);
103 85ad3d82 Assos Assos
    }
104
  }
105
106 560c3060 Julien Enselme
  // Prepare the node to be displayed so all of the regular hooks are triggered.
107
  $default_output = node_page_view($node);
108
109 e4c061ad Assos Assos
  // Otherwise, fall back to the default output generated by node_page_view().
110
  return $default_output;
111 85ad3d82 Assos Assos
}
112
113
/**
114
 * Callback to get arguments provided by this task handler.
115
 *
116
 * Since this is the node view and there is no UI on the arguments, we
117
 * create dummy arguments that contain the needed data.
118
 */
119
function page_manager_node_view_get_arguments($task, $subtask_id) {
120
  return array(
121
    array(
122
      'keyword' => 'node',
123
      'identifier' => t('Node being viewed'),
124
      'id' => 1,
125
      'name' => 'entity_id:node',
126
      'settings' => array(),
127
    ),
128
  );
129
}
130
131
/**
132
 * Callback to get context placeholders provided by this handler.
133
 */
134
function page_manager_node_view_get_contexts($task, $subtask_id) {
135
  return ctools_context_get_placeholders_from_argument(page_manager_node_view_get_arguments($task, $subtask_id));
136
}
137
138
/**
139
 * Callback to enable/disable the page from the UI.
140
 */
141
function page_manager_node_view_enable($cache, $status) {
142
  variable_set('page_manager_node_view_disabled', $status);
143
144
  // Set a global flag so that the menu routine knows it needs
145
  // to set a message if enabling cannot be done.
146
  if (!$status) {
147
    $GLOBALS['page_manager_enabling_node_view'] = TRUE;
148
  }
149
}
150
151
/**
152
 * Callback to determine if a page is accessible.
153
 *
154
 * @param $task
155
 *   The task plugin.
156
 * @param $subtask_id
157
 *   The subtask id
158
 * @param $contexts
159
 *   The contexts loaded for the task.
160
 * @return
161
 *   TRUE if the current user can access the page.
162
 */
163
function page_manager_node_view_access_check($task, $subtask_id, $contexts) {
164
  $context = reset($contexts);
165
  return node_access('view', $context->data);
166
}