patch for better destination
| Project: | Favorite Nodes |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
I created a patch to improve where drupal goes after the fave add/delete actions for this module. By default the module returns to user page (for delete) or the node (for add). Since i have links in teasers lists all over my site for adding item in teaser to fave list this didnt make any sense (as i would guess it doesnt in many cases).
My patch checks if the destination GET has been set and if it has it goes there. The other half of this should likely be to fix the link that the actions use to set the destination. I haven't done this (although it is pretty simple) since i dont use the links created - since i have templated teasers and icons for "add to fave list" i simply have the img url set the dest.
e.g.
if (user_access('create favorite nodes')) {
if (array_key_exists($nid,favorite_nodes_get($user->uid,'content_review')))
$favorites = '<a href="/favorite_nodes/delete/'.$nid.'?destination='.$_GET['q'].'"><img src="/'.$puggit.'/images/add-favorites.gif" title="Remove this review from your favorites list."></a>';
else
$favorites = '<a href="/favorite_nodes/add/'.$nid.'?destination='.$_GET['q'].'"><img src="/'.$puggit.'/images/add-favorites.gif" title="Add this review to your favorites list."></a>';
}
else $favorites = ""; cheers,
Peter Lindstrom
LiquidCMS - Content Management Solution Experts
| Attachment | Size |
|---|---|
| fave_node_destination.patch | 1.02 KB |

#1
btw, in my example (and with this patch)... the fave module actions simply return to the page i was on at the time.
#2
a patch for 5.x would be useful. i'm in favour of returning to the node when removed from favourites
#3
I have patched favorite_nodes for D5 for this issue. I can't paste the patch, because I have other patches pending.
Modify the line that reads:
$links[] = array('title' => t('add to favorites'), 'href' => 'favorite_nodes/add/'. $node->nid);this way:
$links[] = array('title' => t('add to favorites'), 'href' => url('favorite_nodes/add/'. $node->nid, drupal_get_destination(), null, true));and this one
$links[] = array('title' => t('remove from favorites'), 'href' => 'favorite_nodes/delete/'. $node->nid);this way
$links[] = array('title' => t('remove from favorites'), 'href' => url('favorite_nodes/delete/'. $node->nid, drupal_get_destination(), null, true));Then in the favorite_nodes_add_page() function change the simple drupal_goto() call to
if (isset($_GET['destination'])) drupal_goto(url($_GET['destination']));else drupal_goto("node/$nid");
Then in the favorite_nodes_delete_page() function change the simple drupal_goto() call to
if (isset($_GET['destination'])) drupal_goto(url($_GET['destination']));else drupal_goto("user/$user->uid");
You should be done