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