poll.inc 3.7 KB

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