0

I have a use case where I need to redirect a user visiting a page, let's say sprockets/order when a user clicks on an "order" link. We take them to a page with a login field (not user/login, but something with that form). Once they log in, we need to redirect them to that page, or for that matter, any origin page they click from to the login page.

I've looked into a couple of modules, right now Login Destination is the one i'm experimenting with, with no real success, even when its routing is configured to fire from this origin page. I'll keep experimenting with it, but I can't imagine its the only option at hand.

The question ultimately is, with the logic below, is there an approach I can take with how I send users to this specialized login page, and have them return to the origin?

The logic I have for this is as follows:

/**
 * Implements hook_menu()
 */
function hook_sprocket_menu() {
  $items['order/%order_id'] = array(
    "title" => t("Order Sprocket"),
    "page callback" => "example_order_sprocket",
    "page arguments" => array(1),
    'access arguments' => array('interact with orders'),
    "type" => MENU_LOCAL_TASK,
  );

  return $items;
}

/**
 * Routes the order call based on click
 */
function example_order_sprocket($orderid) {
  global $user;

  if(user_is_anonymous()) {
    drupal_goto("custom/user/login"); //The custom login/reg page
  } else {
    //Continue with Order logic here
  }
}
0

You can have destination parameter in url. Something like below.

drupal_goto('custom/user/login', array('query' => array('destination' => current_path())));

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.