patch for better destination

liquidcms - May 3, 2007 - 04:19
Project:Favorite Nodes
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

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

AttachmentSize
fave_node_destination.patch1.02 KB

#1

liquidcms - May 3, 2007 - 04:21

btw, in my example (and with this patch)... the fave module actions simply return to the page i was on at the time.

#2

bobdalob - March 18, 2008 - 14:34

a patch for 5.x would be useful. i'm in favour of returning to the node when removed from favourites

#3

flexer - July 13, 2008 - 16:58
Version:4.7.x-1.x-dev» 5.x-1.x-dev

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

 
 

Drupal is a registered trademark of Dries Buytaert.