Problem
An non-authenticated user navigates his/her website, reviewing the content of each page. Soon, the user encounters a page that he/she would like to edit. The user clicks the "log in" link, and is either: a) redirected back to the front page of the website or b) redirected to a specific page. The problem is that now the user must re-navigate the site back to the page he/she wishes to edit in order to begin the editing process.
Solution
The solution to the problem stated above is to return the user back to the page he/she was viewing before attempting to "log in"
The Patch (against 6.x-1.2)
In order to preserve the current functionality of pubcookie, the patch only works if the "Successful login URL:" setting is empty. So if the administrator has decided that he wants users to be directed to a specific page after "log in" that will still happen. Otherwise, the user will be returned the page they were last viewing.
Comment | File | Size | Author |
---|---|---|---|
pubcookie-return-to-last-viewed.patch | 1.93 KB | Anonymous (not verified) |
Comments
Comment #1
jeastham CreditAttribution: jeastham commentedThanks. While I wish this was a configurable option in the pubcookie module, applying this patch solved my problem.
For a beginner like myself, it was also important to remember that you must pass the destination to pubcookie using a query string for this to work. For example:
or
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commented@jeastham - Glad you've found the patch useful. I know it's been quite useful at my place of work.
Comment #3
jameswoods CreditAttribution: jameswoods commented[Updated code/results, still need help]
Great patch, thanks! 8^)
I would like to add a menu item (like a real drupal menu) that uses the path "login/pc?destination=$_GET['q']" so that whenever this menu is displayed, it has a link that includes the "get back here" functionality your awesome patch provides.
I have the following working great, when it gets put into a tpl.php file (blech!)
<a href="<?php print base_path() . 'login/pc?destination=' . $_GET['q'];?>">Pubcookie login test</a>
However --
The following code puts the menu item into a menu, but the link is always login/pc%3Fdestination%3Dnode/1
and then using drupal_goto in the widget_display_sendtopubcookie function...but I get a white screen with some devel debug info.
Am I on the right track? Is it possible to create a menu item as described above? If not, could you point me in the right direction?
-James
Comment #4
jameswoods CreditAttribution: jameswoods commentedThe following code works for me. I'm admittedly chagrined because I don't completely understand why...I sort of iterated this process until I got something to work: 1) Read about some new function, 2) Try the function how it's supposed to be used, 3) Cry when it didn't, 4) Try every hacky/brute-forcey tactic possible. 5) Repeat 1-4.
Eventually something gave way and I was able to bend Drupal to my will.
Below the code, I'll explain what little I do understand.
$items['login/%dest'] is a 'wildcard' for the special 'to_arg()' function. Essentially, it's a helper function that Drupal can use to produce a replacement (paraphrased from Mr. Awesome, John K. VanDyk, author of Pro Drupal Development 2nd Edition).
By naming a function with the wildcard and appending _to_arg($arg) (e.g. dest_to_arg($arg), I'm able to return some value. In this case, I'm just returning the value of the query string varible 'q' (which ends up being 'node/123' or 'taxonomy/term/3' or whatever).
-James
Comment #5
dalearyous CreditAttribution: dalearyous commentedhow would i do this in d7 ?
Comment #6
jvandyk CreditAttribution: jvandyk commentedThis feature has been added to 7.x-2.0-beta1.
On the configuration page there is a place to enter "Successful Login URL". If that is left empty, the user is now redirected to the page they were on.