0

Hi I have used hook_url_inbound_alter to alter the URL. When I access user/%/order anonymously it should redirect ti user/login. I have used below code

 function module_url_inbound_alter(&$path, $original_path,
 $path_language) {   
  $argument = explode('/', $path);  
  if (!user_is_logged_in() && isset($argument[0]) && $argument[0] == 'user' && isset($argument[2]) && $argument[2] == 'orders') {
      $path = 'user/login';

   } 
}

It redirects the user to login page but my question is how to add destination parameter. Above code redirects localhost/drupal/user/login but I want to add destination paramater such as localhost/drupal/user/login?destination=user/1/order

When I tried to add the desination variable in $path variable

$path = '/user/login?destination=user/1/order;

I am getting the url like this

http://localhost/drupal/user/login%3Fdestination%3Duser/1/order

Instead it should be like this.

http://dt.drop/user/login?destination=user/1/order

How can I achieve this.

2 Answers 2

0

For your particular problem (redirect an anonymous user to user/login), it can be better to redirect on form submit. So, on hook form_submit() you check whether user_is_logged_in(), if not drupal_goto('user/login').

0

Try adding the destination parameter to $_GET as such:

$path = 'user/login';
$_GET['destination'] = 'user/1/order';

The parameter will be picked by whatever interested parties as if it was a part of the original URL. Since the $path is already parsed it doesn't seem to allow to add the ?parameters. This is acceptably clean as all the code is one place, no need to alter the form elsewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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