View source
<?php
function page_manager_user_view_page_manager_tasks() {
return array(
'task type' => 'page',
'title' => t('User profile template'),
'admin title' => t('User profile template'),
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying user profiles at <em>user/%user</em>. If you add variants, you may use selection criteria such as roles or user access to provide different views of user profiles. If no variant is selected, the default Drupal user view will be used. Please note that if you are using pathauto, aliases may make a node to be somewhere else, but as far as Drupal is concerned, they are still at user/%user.'),
'admin path' => 'user/%user',
'task admin' => 'page_manager_user_view_task_admin',
'hook menu' => 'page_manager_user_view_menu',
'hook menu alter' => 'page_manager_user_view_menu_alter',
'handler type' => 'context',
'get arguments' => 'page_manager_user_view_get_arguments',
'get context placeholders' => 'page_manager_user_view_get_contexts',
'disabled' => variable_get('page_manager_user_view_disabled', TRUE),
'enable callback' => 'page_manager_user_view_enable',
);
}
function page_manager_user_view_menu_alter(&$items, $task) {
if (variable_get('page_manager_user_view_disabled', TRUE)) {
return;
}
if ($items['user/%user_uid_optional']['page callback'] == 'user_view' || variable_get('page_manager_override_anyway', FALSE)) {
$items['user/%user_uid_optional']['page callback'] = 'page_manager_user_view';
$items['user/%user_uid_optional']['file path'] = $task['path'];
$items['user/%user_uid_optional']['file'] = $task['file'];
}
else {
variable_set('page_manager_user_view_disabled', TRUE);
if (!empty($GLOBALS['page_manager_enabling_user_view'])) {
drupal_set_message(t('Page manager module is unable to enable user/%user because some other module already has overridden with %callback.', array(
'%callback' => $items['user/%user_uid_optional']['page callback'],
)), 'error');
}
}
}
function page_manager_user_view($account) {
$task = page_manager_get_task('user_view');
ctools_include('context');
ctools_include('context-task-handler');
$contexts = ctools_context_handler_get_task_contexts($task, '', array(
$account,
));
$output = ctools_context_handler_render($task, '', $contexts, array(
$account->uid,
));
if ($output === FALSE) {
module_load_include('inc', 'user', 'user.pages');
$output = user_view($account);
}
else {
$array = array();
user_module_invoke('view', $array, $account);
}
return $output;
}
function page_manager_user_view_get_arguments($task, $subtask_id) {
return array(
array(
'keyword' => 'user',
'identifier' => t('User being viewed'),
'id' => 1,
'name' => 'uid',
'settings' => array(),
),
);
}
function page_manager_user_view_get_contexts($task, $subtask_id) {
return ctools_context_get_placeholders_from_argument(page_manager_user_view_get_arguments($task, $subtask_id));
}
function page_manager_user_view_enable($cache, $status) {
variable_set('page_manager_user_view_disabled', $status);
if (!$status) {
$GLOBALS['page_manager_enabling_user_view'] = TRUE;
}
}