1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
c304a780
|
Assos Assos
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
85ad3d82
|
Assos Assos
|
/**
|
8 |
|
|
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
9 |
|
|
* more information.
|
10 |
|
|
*/
|
11 |
|
|
function page_manager_contact_user_page_manager_tasks() {
|
12 |
|
|
if (!module_exists('contact')) {
|
13 |
|
|
return;
|
14 |
|
|
}
|
15 |
|
|
return array(
|
16 |
c304a780
|
Assos Assos
|
// This is a 'page' task and will fall under the page admin UI.
|
17 |
85ad3d82
|
Assos Assos
|
'task type' => 'page',
|
18 |
|
|
'title' => t('User contact'),
|
19 |
|
|
'admin title' => t('User contact'),
|
20 |
|
|
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying the user contact form at <em>user/%user/contact</em>. If no variant is selected, the default Drupal user contact form will be used.'),
|
21 |
|
|
'admin path' => 'user/%user/contact',
|
22 |
|
|
|
23 |
|
|
// Callback to add items to the page managertask administration form:
|
24 |
|
|
'task admin' => 'page_manager_contact_user_task_admin',
|
25 |
|
|
|
26 |
|
|
'hook menu alter' => 'page_manager_contact_user_menu_alter',
|
27 |
|
|
|
28 |
|
|
// This is task uses 'context' handlers and must implement these to give the
|
29 |
|
|
// handler data it needs.
|
30 |
|
|
'handler type' => 'context', // handler type -- misnamed
|
31 |
|
|
'get arguments' => 'page_manager_contact_user_get_arguments',
|
32 |
|
|
'get context placeholders' => 'page_manager_contact_user_get_contexts',
|
33 |
|
|
|
34 |
|
|
// Allow this to be enabled or disabled:
|
35 |
|
|
'disabled' => variable_get('page_manager_contact_user_disabled', TRUE),
|
36 |
|
|
'enable callback' => 'page_manager_contact_user_enable',
|
37 |
|
|
'access callback' => 'page_manager_contact_user_access_check',
|
38 |
|
|
);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
/**
|
42 |
|
|
* Callback defined by page_manager_contact_user_page_manager_tasks().
|
43 |
|
|
*
|
44 |
|
|
* Alter the user view input so that user view comes to us rather than the
|
45 |
|
|
* normal user view process.
|
46 |
|
|
*/
|
47 |
|
|
function page_manager_contact_user_menu_alter(&$items, $task) {
|
48 |
|
|
if (variable_get('page_manager_contact_user_disabled', TRUE)) {
|
49 |
|
|
return;
|
50 |
|
|
}
|
51 |
|
|
$callback = $items['user/%user/contact']['page callback'];
|
52 |
|
|
if ($callback == 'drupal_get_form') {
|
53 |
|
|
$callback = $items['user/%user/contact']['page arguments'][0];
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
// Override the user view handler for our purpose.
|
57 |
|
|
if ($callback == 'contact_personal_form' || variable_get('page_manager_override_anyway', FALSE)) {
|
58 |
|
|
$items['user/%user/contact']['page callback'] = 'page_manager_contact_user';
|
59 |
|
|
$items['user/%user/contact']['file path'] = $task['path'];
|
60 |
|
|
$items['user/%user/contact']['file'] = $task['file'];
|
61 |
|
|
}
|
62 |
|
|
else {
|
63 |
c304a780
|
Assos Assos
|
// Automatically disable this task if it cannot be enabled.
|
64 |
85ad3d82
|
Assos Assos
|
variable_set('page_manager_contact_user_disabled', TRUE);
|
65 |
|
|
if (!empty($GLOBALS['page_manager_enabling_contact_user'])) {
|
66 |
|
|
drupal_set_message(t('Page manager module is unable to enable user/%user/contact because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
/**
|
72 |
|
|
* Entry point for our overridden user view.
|
73 |
|
|
*
|
74 |
|
|
* This function asks its assigned handlers who, if anyone, would like
|
75 |
|
|
* to run with it. If no one does, it passes through to Drupal core's
|
76 |
|
|
* user view, which is user_page_view().
|
77 |
|
|
*/
|
78 |
|
|
function page_manager_contact_user($form_id, $account) {
|
79 |
|
|
// Load my task plugin:
|
80 |
|
|
$task = page_manager_get_task('contact_user');
|
81 |
|
|
|
82 |
|
|
// Load the account into a context.
|
83 |
|
|
ctools_include('context');
|
84 |
|
|
ctools_include('context-task-handler');
|
85 |
|
|
$contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
|
86 |
|
|
|
87 |
|
|
$output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
|
88 |
|
|
if ($output !== FALSE) {
|
89 |
|
|
return $output;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
module_load_include('inc', 'contact', 'contact.pages');
|
93 |
|
|
$function = 'contact_personal_form';
|
94 |
|
|
foreach (module_implements('page_manager_override') as $module) {
|
95 |
|
|
$call = $module . '_page_manager_override';
|
96 |
|
|
if (($rc = $call('contact_user')) && function_exists($rc)) {
|
97 |
|
|
$function = $rc;
|
98 |
|
|
break;
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
// Otherwise, fall back.
|
103 |
|
|
return drupal_get_form($function, $account);
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
/**
|
107 |
|
|
* Callback to get arguments provided by this task handler.
|
108 |
|
|
*
|
109 |
|
|
* Since this is the node view and there is no UI on the arguments, we
|
110 |
|
|
* create dummy arguments that contain the needed data.
|
111 |
|
|
*/
|
112 |
|
|
function page_manager_contact_user_get_arguments($task, $subtask_id) {
|
113 |
|
|
return array(
|
114 |
|
|
array(
|
115 |
|
|
'keyword' => 'user',
|
116 |
|
|
'identifier' => t('User being viewed'),
|
117 |
|
|
'id' => 1,
|
118 |
|
|
'name' => 'uid',
|
119 |
|
|
'settings' => array(),
|
120 |
|
|
),
|
121 |
|
|
);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
/**
|
125 |
|
|
* Callback to get context placeholders provided by this handler.
|
126 |
|
|
*/
|
127 |
|
|
function page_manager_contact_user_get_contexts($task, $subtask_id) {
|
128 |
|
|
return ctools_context_get_placeholders_from_argument(page_manager_contact_user_get_arguments($task, $subtask_id));
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
/**
|
132 |
|
|
* Callback to enable/disable the page from the UI.
|
133 |
|
|
*/
|
134 |
|
|
function page_manager_contact_user_enable($cache, $status) {
|
135 |
|
|
variable_set('page_manager_contact_user_disabled', $status);
|
136 |
|
|
|
137 |
|
|
// Set a global flag so that the menu routine knows it needs
|
138 |
|
|
// to set a message if enabling cannot be done.
|
139 |
|
|
if (!$status) {
|
140 |
|
|
$GLOBALS['page_manager_enabling_contact_user'] = TRUE;
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
/**
|
145 |
|
|
* Callback to determine if a page is accessible.
|
146 |
|
|
*
|
147 |
|
|
* @param $task
|
148 |
|
|
* The task plugin.
|
149 |
|
|
* @param $subtask_id
|
150 |
|
|
* The subtask id
|
151 |
|
|
* @param $contexts
|
152 |
|
|
* The contexts loaded for the task.
|
153 |
c304a780
|
Assos Assos
|
*
|
154 |
85ad3d82
|
Assos Assos
|
* @return
|
155 |
|
|
* TRUE if the current user can access the page.
|
156 |
|
|
*/
|
157 |
|
|
function page_manager_blog_contact_user_access_check($task, $subtask_id, $contexts) {
|
158 |
|
|
$context = reset($contexts);
|
159 |
|
|
return _contact_personal_tab_access($context->data);
|
160 |
|
|
} |