Im using hybridauth to let users login from different social media websites ... I send emails manually to some users with an link to edit specific nodes (for example http://example.com/node/444/edit?parma1=val1&param2=val2). At that moment the user is automatically redirected to a page to choose a social media he want to login with. Im using hook_init for this :

function MYMODULE_init(){
  if($node->type == 'type' && other conditions){

Now I want that user to be automatically redirected to that link sent via email after success login via hybridauth ( I tried to add destination query inside drupal_goto but not working.)

how can I do this redirection ?

Thanks in advance.

1 Answer 1


How did you try to add the 'destination' query? It should be something like this:

$query_array = array('param1' => 'value1', 'destination' => 'original_path');
$options = array(
  'query' => query_array,
drupal_goto('link_to_hybridauth_login_page', $options);

Basically, it's important that the destination is passed as part of the $options['query'].

If that doesn't work, try and add your own hook_user_login(), to pick up the 'destination' (or whatever parameter you want to use for the original URL, and redirect the user accordingly). Like:

if (isset($_GET['destination'])) {

You can see an example implementation of hook_user_login in the user_homepage module code: http://cgit.drupalcode.org/user_homepage/tree/user_homepage.module?id=6803e00

Hope this helps with your problem.

EDIT: The hook_user_login() is meant to be something additional to the hook_init() logic you were trying, but not to replace it. Thought I'd just clarify that =).

EDIT 2: Ok, So if I'm getting the problem right, you need to get not only the 'node/xxx/edit' part of the URL, which you have already sorted (right?) but you need to also get all the params of the incoming URL.

Basically, you need to use drupal_get_query_parameters() for that. So you could assemble the $options array like this:

  $current_query_params = drupal_get_query_parameters();
  // Pick up URL and treat params as you need, and prepare query array with 
  // the 'destination' desired, assembled with data from $current_query_params.
  $new_query_array = array();  
  $options = array(
    'query' => $new_query_array,

Hope I'm getting it right now. The linked drupal code from user_homepage uses these functions for a very similar scenario. Look at user_homepage_build_homepage_path_from_request() and user_homepage_user_login() functions.

  • the problem is not how do i use destination query, but how to pass this edit node url to this query ? Apr 3, 2015 at 11:05
  • because when user try to connect via hybridauth, I can't access to this node anymore. Apr 3, 2015 at 11:06

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.