View source
<?php
function user_pages_user_password_page_manager_tasks() {
return array(
'task type' => 'page',
'title' => t('User Password Page'),
'admin title' => t('User Password Page'),
'admin description' => t('When enabled, this overrides the default Drupal behavior for the user password page at <em>/user</em>.'),
'admin path' => 'user/password',
'hook menu alter' => 'user_pages_user_user_password_menu_alter',
'handler type' => 'context',
'disabled' => variable_get('user_pages_user_user_password_disabled', TRUE),
'enable callback' => 'user_pages_user_user_password_enable',
);
}
function user_pages_user_user_password_menu_alter(&$items, $task) {
if (variable_get('user_pages_user_user_password_disabled', TRUE)) {
return;
}
$is_default = $items['user/password']['page callback'] == 'drupal_get_form' && $items['user/password']['page arguments'] == array(
'user_pass',
);
if ($is_default || variable_get('user_pages_override_anyway', FALSE)) {
$items['user/password']['page callback'] = 'user_pages_user_user_password';
unset($items['user/password']['page arguments']);
$items['user/password']['file path'] = $task['path'];
$items['user/password']['file'] = $task['file'];
}
else {
variable_set('user_pages_user_user_password_disabled', TRUE);
if (!empty($GLOBALS['user_pages_user_enabling_user_password'])) {
drupal_set_message(t('Page manager module is unable to enable this page because some other module already has overridden with %callback.', array(
'%callback' => $callback,
)), 'warning');
}
return;
}
}
function user_pages_user_user_password() {
global $user;
$admin = user_access('administer users');
if (!$admin && $user->uid) {
drupal_goto('user/' . $user->uid);
}
$task = page_manager_get_task('user_password');
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', 'user', 'user.pages');
$function = NULL;
foreach (module_implements('page_manager_override') as $module) {
$call = $module . '_page_manager_override';
if (($rc = $call('user_password')) && function_exists($rc)) {
$function = $rc;
break;
}
}
if ($function) {
return $function();
}
return drupal_get_form('user_pass');
}
function user_pages_user_user_password_enable($cache, $status) {
variable_set('user_pages_user_user_password_disabled', $status);
if (!$status) {
$GLOBALS['user_pages_user_enabling_user_password'] = TRUE;
}
}