' . t('About') . ''; $output .= '
' . t('The Login Destination module allows you to customize the destination that the user is redirected to after logging in, registering to the site, using a one-time login link or logging out. The destination can be an internal page or an external URL. You may specify certain conditions like pages or user roles and make the destination depend upon them. You may also use a PHP snippets to provide custom conditions and destinations. Note that PHP Filter module has to be enabled and you have to be granted the "Use PHP for settings" permissions to be able to enter PHP code.') . '
'; return $output; case 'admin/config/people/login-destination': return '' . t('Login destination rules are evaluated each time a user logs in, registers to the site, uses a one-time login link or logs out. Each rule consists of the destination, path conditions and user roles conditions. First matching rule gets executed.') . '
'; } } /** * Implements hook_permission(). */ function login_destination_permission() { return array( 'administer login destination settings' => array( 'title' => t('Administer Login Destination settings'), ), ); } /** * Implements hook_menu(). */ function login_destination_menu() { $items['admin/config/people/login-destination'] = array( 'title' => 'Login destinations', 'description' => 'Customize the destination that the user is redirected to after login.', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_overview_form'), 'access arguments' => array('administer login destination settings'), 'file' => 'login_destination.admin.inc', 'weight' => 10, ); $items['admin/config/people/login-destination/add'] = array( 'title' => 'Add login destination rule', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_edit_form'), 'access arguments' => array('administer login destination settings'), 'type' => MENU_LOCAL_ACTION, 'weight' => 1, 'file' => 'login_destination.admin.inc', ); $items['admin/config/people/login-destination/edit/%login_destination'] = array( 'title' => 'Edit login destination rule', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_edit_form', 5), 'access arguments' => array('administer login destination settings'), 'file' => 'login_destination.admin.inc', ); $items['admin/config/people/login-destination/delete/%login_destination'] = array( 'title' => 'Delete login destination rule', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_delete_form', 5), 'access arguments' => array('administer login destination settings'), 'file' => 'login_destination.admin.inc', ); $items['admin/config/people/login-destination/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['admin/config/people/login-destination/settings'] = array( 'title' => 'Settings', 'description' => 'Change Login Destination settings.', 'page callback' => 'drupal_get_form', 'page arguments' => array('login_destination_settings'), 'access arguments' => array('administer login destination settings'), 'type' => MENU_LOCAL_TASK, 'file' => 'login_destination.admin.inc', 'weight' => 10, ); return $items; } /** * Load a login destination. */ function login_destination_load($id) { $result = db_select('login_destination', 'l') ->fields('l') ->condition('id', $id) ->execute() ->fetchAssoc(); $result['triggers'] = unserialize($result['triggers']); if (empty($result['triggers'])) { $result['triggers'] = array(); } $result['roles'] = unserialize($result['roles']); if (empty($result['roles'])) { $result['roles'] = array(); } return $result; } /** * Implements hook_theme(). */ function login_destination_theme() { return array( 'login_destination_destination' => array( 'variables' => array('destination' => NULL), 'file' => 'login_destination.admin.inc', ), 'login_destination_pages' => array( 'variables' => array('pages' => NULL, 'pages_type' => 0), 'file' => 'login_destination.admin.inc', ), 'login_destination_triggers' => array( 'variables' => array('items' => NULL), 'file' => 'login_destination.admin.inc', ), 'login_destination_roles' => array( 'variables' => array('items' => NULL), 'file' => 'login_destination.admin.inc', ), 'login_destination_overview_form' => array( 'file' => 'login_destination.admin.inc', 'render element' => 'form', ), ); } /** * Implements hook_form_alter(). */ function login_destination_form_alter(&$form, &$form_state, $form_id) { // We redirect by using the drupal_goto_alter hook. If we simply // call drupal_goto() it may break compatibility with other modules. If we set // the $_GET['destination'] variable we will loose the possibility to redirect // to an external URL. // Please note the the system_goto_action() calls drupal_goto() // More on this issue http://drupal.org/node/732542. // If we add the $form_state['redirect'] here it will be overridden by the // user_login_submit(). So we add a submit handler instead and will set the // redirect later. Our submit handler will be executed after the execution // of user_login_submit(). This is because form_submit() functions are // appended to form before hook_form_alter() is executed. // We will execute also after LoginToboggan's function as it replaces the // original submit function from user module. switch ($form_id) { // User register page and user login page. case 'user_register_form': case 'user_login': $form['#validate'][] = 'login_destination_validate'; break; } switch ($form_id) { // One-time login, password reset. case 'user_profile_form': if (isset($_GET['pass-reset-token'])) { // Redirect only from user_pass_reset // You have to explicitally turn on the option to always redirect from // the profile page. This is for constistency. $form['#submit'][] = 'login_destination_submit'; break; } } } /** * Helper submit function. */ function login_destination_validate($form, &$form_state) { // LoginToboggan's unified page is rendered dynamically. Fix it. switch ($form['#form_id']) { case 'user_register_form': if (drupal_match_path($_GET['q'], 'user')) { $_GET['q'] = 'user/register'; } break; case 'user_login': if (drupal_match_path($_GET['q'], 'user/register')) { $_GET['q'] = 'user'; } break; } // Fix the current page in case of 403 page. if ($form['#form_id'] == 'user_login') { if (drupal_get_http_header('Status') == '403 Forbidden') { $_GET['current'] = $_GET['destination']; } } } /** * Helper submit function. */ function login_destination_submit($form, &$form_state) { login_destination_perform_redirect('login'); } /** * Implements hook_menu_link_alter(). */ function login_destination_menu_link_alter(&$item) { // Flag a link to be altered by hook_translated_menu_link_alter(). // This is called only on menu rebuild, so we have to add this information // manually to the database on install. Clearing caches also helps. $paths = array('user/logout', 'user/login', 'user'); if (in_array($item['link_path'], $paths)) { $item['options']['alter'] = TRUE; } } /** * Implements hook_translated_menu_link_alter(). */ function login_destination_translated_menu_link_alter(&$item, $map) { $paths = array('user/login', 'user'); // Append the current path to URL. if ($item['link_path'] == 'user/logout' || (in_array($item['link_path'], $paths) && user_is_anonymous()) ) { $current = $_GET['q']; if ($current == '