contact_site.inc 4.1 KB

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