comparison sites/all/modules/ctools/page_manager/plugins/tasks/poll.inc @ 0:ff03f76ab3fe

initial version
author danieleb <danielebarchiesi@me.com>
date Wed, 21 Aug 2013 18:51:11 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ff03f76ab3fe
1 <?php
2
3 /**
4 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
5 * more information.
6 */
7 function page_manager_poll_page_manager_tasks() {
8 if (!module_exists('poll')) {
9 return;
10 }
11
12 return array(
13 // This is a 'page' task and will fall under the page admin UI
14 'task type' => 'page',
15
16 'title' => t('All polls'),
17 'admin title' => t('All polls'),
18 'admin description' => t('When enabled, this overrides the default Drupal behavior for the polls at <em>/poll</em>. If no variant is selected, the default Drupal most recent polls will be shown.'),
19 'admin path' => 'poll',
20
21 // Menu hooks so that we can alter the node/%node menu entry to point to us.
22 'hook menu alter' => 'page_manager_poll_menu_alter',
23
24 // This is task uses 'context' handlers and must implement these to give the
25 // handler data it needs.
26 'handler type' => 'context',
27
28 // Allow this to be enabled or disabled:
29 'disabled' => variable_get('page_manager_poll_disabled', TRUE),
30 'enable callback' => 'page_manager_poll_enable',
31 'access callback' => 'page_manager_poll_access_check',
32 );
33 }
34
35 /**
36 * Callback defined by page_manager_poll_page_manager_tasks().
37 *
38 * Alter the node edit input so that node edit comes to us rather than the
39 * normal node edit process.
40 */
41 function page_manager_poll_menu_alter(&$items, $task) {
42 if (variable_get('page_manager_poll_disabled', TRUE)) {
43 return;
44 }
45
46 $callback = $items['poll']['page callback'];
47 // Override the node edit handler for our purpose.
48 if ($callback == 'poll_page' || variable_get('page_manager_override_anyway', FALSE)) {
49 $items['poll']['page callback'] = 'page_manager_poll';
50 $items['poll']['file path'] = $task['path'];
51 $items['poll']['file'] = $task['file'];
52 }
53 else {
54 variable_set('page_manager_poll_disabled', TRUE);
55 if (!empty($GLOBALS['page_manager_enabling_poll'])) {
56 drupal_set_message(t('Page manager module is unable to enable poll because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning');
57 }
58 return;
59 }
60
61 }
62
63 /**
64 * Entry point for our overridden node edit.
65 *
66 * This function asks its assigned handlers who, if anyone, would like
67 * to run with it. If no one does, it passes through to Drupal core's
68 * node edit, which is node_page_edit().
69 */
70 function page_manager_poll() {
71 // Load my task plugin
72 $task = page_manager_get_task('poll');
73
74 ctools_include('context');
75 ctools_include('context-task-handler');
76 $output = ctools_context_handler_render($task, '', array(), array());
77 if ($output !== FALSE) {
78 return $output;
79 }
80
81 module_load_include('inc', 'poll', 'poll.pages');
82 $function = 'poll_page';
83 foreach (module_implements('page_manager_override') as $module) {
84 $call = $module . '_page_manager_override';
85 if (($rc = $call('poll')) && function_exists($rc)) {
86 $function = $rc;
87 break;
88 }
89 }
90
91 // Otherwise, fall back.
92 return $function();
93 }
94
95 /**
96 * Callback to enable/disable the page from the UI.
97 */
98 function page_manager_poll_enable($cache, $status) {
99 variable_set('page_manager_poll_disabled', $status);
100 // Set a global flag so that the menu routine knows it needs
101 // to set a message if enabling cannot be done.
102 if (!$status) {
103 $GLOBALS['page_manager_enabling_poll'] = TRUE;
104 }
105 }
106
107 /**
108 * Callback to determine if a page is accessible.
109 *
110 * @param $task
111 * The task plugin.
112 * @param $subtask_id
113 * The subtask id
114 * @param $contexts
115 * The contexts loaded for the task.
116 * @return
117 * TRUE if the current user can access the page.
118 */
119 function page_manager_poll_access_check($task, $subtask_id, $contexts) {
120 return user_access('access content');
121 }