contact_site.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_contact_site_page_manager_tasks() {
  7. if (!module_exists('contact')) {
  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('Site contact page'),
  14. 'admin title' => t('Site contact page'),
  15. 'admin description' => t('When enabled, this overrides the default Drupal behavior for the site contact page at <em>/contact</em>. If no variant is selected, the default Drupal contact form will be used.'),
  16. 'admin path' => 'contact',
  17. // Menu hooks so that we can alter the node/%node menu entry to point to us.
  18. 'hook menu alter' => 'page_manager_contact_site_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_contact_site_disabled', TRUE),
  24. 'enable callback' => 'page_manager_contact_site_enable',
  25. 'access callback' => 'page_manager_contact_access_check',
  26. );
  27. }
  28. /**
  29. * Callback defined by page_manager_contact_site_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_contact_site_menu_alter(&$items, $task) {
  35. if (variable_get('page_manager_contact_site_disabled', TRUE)) {
  36. return;
  37. }
  38. $callback = $items['contact']['page callback'];
  39. if ($callback == 'drupal_get_form') {
  40. $callback = $items['contact']['page arguments'][0];
  41. }
  42. // Override the node edit handler for our purpose.
  43. if ($callback == 'contact_site_form' || variable_get('page_manager_override_anyway', FALSE)) {
  44. $items['contact']['page callback'] = 'page_manager_contact_site';
  45. $items['contact']['file path'] = $task['path'];
  46. $items['contact']['file'] = $task['file'];
  47. }
  48. else {
  49. variable_set('page_manager_contact_site_disabled', TRUE);
  50. if (!empty($GLOBALS['page_manager_enabling_contact_site'])) {
  51. drupal_set_message(t('Page manager module is unable to enable contact because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning');
  52. }
  53. return;
  54. }
  55. }
  56. /**
  57. * Entry point for our overridden site contact.
  58. *
  59. * This function asks its assigned handlers who, if anyone, would like
  60. * to run with it. If no one does, it passes through to Drupal core's
  61. * node edit, which is node_page_edit().
  62. */
  63. function page_manager_contact_site() {
  64. // Load my task plugin
  65. $task = page_manager_get_task('contact_site');
  66. ctools_include('context');
  67. ctools_include('context-task-handler');
  68. $output = ctools_context_handler_render($task, '', array(), array());
  69. if ($output !== FALSE) {
  70. return $output;
  71. }
  72. module_load_include('inc', 'contact', 'contact.pages');
  73. $function = 'contact_site_form';
  74. foreach (module_implements('page_manager_override') as $module) {
  75. $call = $module . '_page_manager_override';
  76. if (($rc = $call('contact_site')) && function_exists($rc)) {
  77. $function = $rc;
  78. break;
  79. }
  80. }
  81. // Otherwise, fall back.
  82. if ($function == 'contact_site_form') {
  83. return drupal_get_form($function);
  84. }
  85. return $function();
  86. }
  87. /**
  88. * Callback to enable/disable the page from the UI.
  89. */
  90. function page_manager_contact_site_enable($cache, $status) {
  91. variable_set('page_manager_contact_site_disabled', $status);
  92. // Set a global flag so that the menu routine knows it needs
  93. // to set a message if enabling cannot be done.
  94. if (!$status) {
  95. $GLOBALS['page_manager_enabling_contact_site'] = TRUE;
  96. }
  97. }
  98. /**
  99. * Callback to determine if a page is accessible.
  100. *
  101. * @param $task
  102. * The task plugin.
  103. * @param $subtask_id
  104. * The subtask id
  105. * @param $contexts
  106. * The contexts loaded for the task.
  107. * @return
  108. * TRUE if the current user can access the page.
  109. */
  110. function page_manager_contact_access_check($task, $subtask_id, $contexts) {
  111. return user_access('access site-wide contact form');
  112. }