Users must be logged in to see anything on my site; so it's important the user login block is always shown to anonymous users.

When users log out, they are normally redirected to the front page. A user has reported an issue where this doesn't happen; the user is kept at /user/logout, where the blocks are not shown.

If I manually navigate to that address, the redirection to the front page doesn't always happen to me, and I can also see that no blocks are shown.

  • Are you looking for a way to show the blocks also on the /user/logout page, or to be sure the redirection always happens? – kiamlaluno Nov 24 '12 at 15:16
  • If there was a way of making the blocks always show that seems like a more robust solution. – Evanss Nov 24 '12 at 15:32
  • When the redirection to the front page doesn't happen, do you see an "Access denied" message, or do you see something else? – kiamlaluno Nov 24 '12 at 15:41
  • I see the "Access denied" message. – Evanss Nov 24 '12 at 15:51
  • That is what I suspected: It's the only case where the redirection doesn't happen. I will write an answer as soon as possible. – kiamlaluno Nov 24 '12 at 16:25

If there aren't modules that avoid the redirection happens, the only case the redirection from user/logout to the front page doesn't happen is when the user is already logged out. user/logout is defined as the following, in user_menu().

  $items['user/logout'] = array(
    'title' => 'Log out', 
    'access callback' => 'user_is_logged_in', 
    'page callback' => 'user_logout', 
    'weight' => 10, 
    'menu_name' => 'user-menu', 
    'file' => 'user.pages.inc',

When a menu is accessed from the users, Drupal first calls the access callback; if the access callback returns TRUE, then Drupal calls the page callback. In this case, the redirection is done from the page callback, which is never called when the user is logged out. (In that case, user_is_logged_in() returns FALSE.)

For a page like user/logout, the login block is not shown. In fact, user_block_view() contains the following code, used to render the login block.

  // For usability's sake, avoid showing two login forms on one page.
  if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
    $block['subject'] = t('User login');
    $block['content'] = drupal_get_form('user_login_block');
  return $block;

What you can do is implementing hook_block_view_MODULE_DELTA_alter() to show the login block also on user/logout, in the case the redirection to the front page doesn't happen for any reason.

function mymodule_block_view_user_login_alter(&$data, $block) {
  if (!$GLOBALS['user']->uid && $_GET['q'] == 'user/logout') {
    $data['subject'] = t('User login');
    $data['content'] = drupal_get_form('user_login_block');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.