Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  jdln 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. –  jdln 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

1 Answer 1

up vote 0 down vote accepted

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');
  }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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