2

I have a link for users to click so that they can add a specific node type, and I use a link like below so that if the user isn't logged in, he/she can login and then be redirected to the node form, and if already is, directly goes to that form.

Now, if the user isn't registered yet, and clicks the register tab instead when coming to /user (or /user/login), the destination argument disappears, and when the user has filled out the form and is all set, he/she will be forwarded to the start page, and not the node form, that I wanted.

What would I have to do to keep this destination argument if the users registers in the process?

I tried Rules - nothing. And now I'm trying to use form/menu alter to either add the destination argument to the link, or create a completely new tab for this, and hide the other one.

Help!

Url example: example.org/user/login?destination=/node/add/help

5 Answers 5

2

I found for Drupal 7 there is no need to override the theme function, just adding a preprocess hook is enough.

/**
 * Add destination param to user tabs if set.
 * Implements HOOK_preprocess_menu_local_task()
 */
function THEME_preprocess_menu_local_task(&$variables) {
    $link = &$variables['element']['#link'];
    // check for $_GET['destination'] because drupal_get_destination() always contains at least the current page
    if ($link['tab_root'] === 'user' && !empty($_GET['destination'])) {
      $link['localized_options']['query'] = drupal_get_destination();
    }
}

Replace THEME with the name of your theme or module.

1

If you know how to do a little bit of theming or are happy editing a php file then you can do this by theming your menu links. I wrote a solution for Drupal 6 here http://tappetyclick.com/blog/2013/04/11/maintain-destination-drupal-user-account-menu#.UWbt8hcmdIE because I found it so hard to find a solution myself.

Hope that helps someone

0

I'll use JavaScript (jQuery) and set a cookie instead.

0

For Drupal 7:

/**
 * THEME_menu_local_task override.
 * Add destination param to user tabs if set.
 */
function THEME_menu_local_task(array $variables) {
  $link = $variables['link']['#link'];

  if ($link['tab_root'] == 'user' && !empty($_GET['destination'])) {
      $link['localized_options']['query'] = drupal_get_destination();
    }
      $output = l($link['title'], $link['href'], $link['localized_options']);
      return '<li' . (!empty($variables['link']['#active']) ? ' class="active"' : '') . '>' . l($link['title'], $link['href'], $link['localized_options']) . "</li>\n";
}

Place in your template.php or a custom module. Replace THEME with your theme name.

0

For Drupal 8 there is a tiny module just doing that:
https://www.drupal.org/project/user_login_persistent_destination

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.