开发者

Issues with hook_user and redirecting logout in Drupal

开发者 https://www.devze.com 2023-02-17 14:22 出处:网络
Okay so I\'m trying to customize a different logout destination other than the frontpage with the following module:

Okay so I'm trying to customize a different logout destination other than the frontpage with the following module:


function mymodule_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {

    case 'logout':

        $_REQUEST['destination'] = 'user';

      break;

    default:

      break;
  }
}

It would be nice if I could redirect users on my site back to the login form after they logout, but this doesn't seem to work. I tried a fresh install and can't seem to get it working there either.

Am I missing something here?

Edit:

I seem to be able to place a case for changing the login and it works, but the logout doesn't seem to fire in the same way, even without a case for login:


function mymodule_user(开发者_StackOverflow中文版$op, &$edit, &$account, $category = NULL) {
  global $user;
  switch ($op) {

    case 'logout':

        drupal_goto('user');

      break;
    case 'login':

        $dest  = $arr[0];
        $_REQUEST['destination'] = $dest;

      break;

    default:

      break;
  }
}


You may add:

unset($edit['destination']); 

After:

$_REQUEST['destination'] = $dest;


function MY_MODULE_user($op, &$edit, &$account, $category = NULL) {
  global $user;
  switch ($op) {
    case 'logout':
      drupal_goto('user');
      break;
  }
}


You can use this with Rules instead of code.

But if it is not working, there may be a drupal_goto() interfering elsewhere.

You should also put in a watchdog call inside of the logout case to know that your hook fired.

0

精彩评论

暂无评论...
验证码 换一张
取 消