1 |
85ad3d82
|
Assos Assos
|
<?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_contact_site_page_manager_tasks() {
|
8 |
|
|
if (!module_exists('contact')) {
|
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('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 |
|
|
|
21 |
|
|
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
22 |
|
|
'hook menu alter' => 'page_manager_contact_site_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_contact_site_disabled', TRUE),
|
30 |
|
|
'enable callback' => 'page_manager_contact_site_enable',
|
31 |
|
|
'access callback' => 'page_manager_contact_access_check',
|
32 |
|
|
);
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* Callback defined by page_manager_contact_site_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_contact_site_menu_alter(&$items, $task) {
|
42 |
|
|
if (variable_get('page_manager_contact_site_disabled', TRUE)) {
|
43 |
|
|
return;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
$callback = $items['contact']['page callback'];
|
47 |
|
|
if ($callback == 'drupal_get_form') {
|
48 |
|
|
$callback = $items['contact']['page arguments'][0];
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
// Override the node edit handler for our purpose.
|
52 |
|
|
if ($callback == 'contact_site_form' || variable_get('page_manager_override_anyway', FALSE)) {
|
53 |
|
|
$items['contact']['page callback'] = 'page_manager_contact_site';
|
54 |
|
|
$items['contact']['file path'] = $task['path'];
|
55 |
|
|
$items['contact']['file'] = $task['file'];
|
56 |
|
|
}
|
57 |
|
|
else {
|
58 |
|
|
variable_set('page_manager_contact_site_disabled', TRUE);
|
59 |
|
|
if (!empty($GLOBALS['page_manager_enabling_contact_site'])) {
|
60 |
|
|
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');
|
61 |
|
|
}
|
62 |
|
|
return;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
/**
|
68 |
|
|
* Entry point for our overridden site contact.
|
69 |
|
|
*
|
70 |
|
|
* This function asks its assigned handlers who, if anyone, would like
|
71 |
|
|
* to run with it. If no one does, it passes through to Drupal core's
|
72 |
|
|
* node edit, which is node_page_edit().
|
73 |
|
|
*/
|
74 |
|
|
function page_manager_contact_site() {
|
75 |
|
|
// Load my task plugin
|
76 |
|
|
$task = page_manager_get_task('contact_site');
|
77 |
|
|
|
78 |
|
|
ctools_include('context');
|
79 |
|
|
ctools_include('context-task-handler');
|
80 |
|
|
$output = ctools_context_handler_render($task, '', array(), array());
|
81 |
|
|
if ($output !== FALSE) {
|
82 |
|
|
return $output;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
module_load_include('inc', 'contact', 'contact.pages');
|
86 |
|
|
$function = 'contact_site_form';
|
87 |
|
|
foreach (module_implements('page_manager_override') as $module) {
|
88 |
|
|
$call = $module . '_page_manager_override';
|
89 |
|
|
if (($rc = $call('contact_site')) && function_exists($rc)) {
|
90 |
|
|
$function = $rc;
|
91 |
|
|
break;
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
// Otherwise, fall back.
|
96 |
|
|
if ($function == 'contact_site_form') {
|
97 |
|
|
return drupal_get_form($function);
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
return $function();
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/**
|
104 |
|
|
* Callback to enable/disable the page from the UI.
|
105 |
|
|
*/
|
106 |
|
|
function page_manager_contact_site_enable($cache, $status) {
|
107 |
|
|
variable_set('page_manager_contact_site_disabled', $status);
|
108 |
|
|
// Set a global flag so that the menu routine knows it needs
|
109 |
|
|
// to set a message if enabling cannot be done.
|
110 |
|
|
if (!$status) {
|
111 |
|
|
$GLOBALS['page_manager_enabling_contact_site'] = TRUE;
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
/**
|
116 |
|
|
* Callback to determine if a page is accessible.
|
117 |
|
|
*
|
118 |
|
|
* @param $task
|
119 |
|
|
* The task plugin.
|
120 |
|
|
* @param $subtask_id
|
121 |
|
|
* The subtask id
|
122 |
|
|
* @param $contexts
|
123 |
|
|
* The contexts loaded for the task.
|
124 |
|
|
* @return
|
125 |
|
|
* TRUE if the current user can access the page.
|
126 |
|
|
*/
|
127 |
|
|
function page_manager_contact_access_check($task, $subtask_id, $contexts) {
|
128 |
|
|
return user_access('access site-wide contact form');
|
129 |
|
|
} |