how to implement 'one click friend request'

ncameron - October 9, 2008 - 16:27
Project:User Relationships
Version:5.x-2.8
Component:User interface
Category:support request
Priority:minor
Assigned:alex.k
Status:closed
Description

Hi there,

I was wondering what is the best way to create a button to add a relationship? On our site we only have one type of relationship defined ('friend'). I want to add a button to the bio page (via php, in the node-bio.tpl.php file) which will allow me to add the person as a friend.

I was thinking of somehow using the same code which generates the 'create' button you see on the page: /relationship/request/$uid. Only problem is, I can't find the code in the module files. Any tips?

Thanks so much for any help you can offer,

Neil

#1

ncameron - October 10, 2008 - 08:22

So I had a go at scratching my own itch and came up with the below code. It needs wrapping in an if statement to ensure it doesn't show on the pages of users who are already friends. Anyone have any thoughts about this code? Any problems with it?

<?php
// set up variables
global $user;
$uid = $user->uid;

// when clicked do this
if (isset($_POST['add_submit'])) {
   
user_relationships_request_relationship ($uid,$node->uid,5,false);
   
drupal_set_message(t('your friend request has been submitted'));

}
?>



<form method="post" action="<?php echo $PHP_SELF;?>">
   <input type="submit" name="add_submit" value="add as friend" id="add_submit">
</form>

Cheers,

Neil

#2

alex.k - October 10, 2008 - 08:34

Looks good. I haven't done much theming of this kind before, so I assume the submit action will get through to the page.

You might want to look at #246397: Plugin: direct relationship urls instead of select form, having this you can just add a link with a destination parameter to make it work. There will still be the confirmation screen 'are you sure you want to add ...'

#3

scottrigby - October 30, 2008 - 20:41
Version:5.x-2.8» 6.x-1.x-dev

hi Alex,

Can you elaborate slightly about how to manually print the links that are in the current 6.x-1.x-dev version?

I was followed the link you added to this issue #319809: Add to friends, become a fan 2 buttons here, and now realize that what I'm looking for might not be documented yet. This issue seems like a good place to ask...

What I'm trying to do is make a view that lists all users' profile nodes (using Content Profile module). If I could manually print the friend request link (not button, but link like you've done in the current dev version) that would really make my day.

Thanks in advance :)
Scott

#4

alex.k - November 1, 2008 - 16:35
Version:6.x-1.x-dev» 5.x-2.8

Scott, this would have been best as a new issue, as this one is about 5.x...

I'm assuming this is about Views, the project. For this you have a couple of options:
- implement a new Views field, which would render a link for a given relationship based on its status (add, approve/reject, delete) with the author of the node
- Add a custom template for nodes being shown by the view, and create links there. Actual links are right now created in _user_relationships_ui_between($viewer, $account) and _user_relationships_ui_actions_between($viewer, $account) as examples.
Are you handy with either task?

#5

alex.k - July 6, 2009 - 20:49
Assigned to:Anonymous» alex.k
Status:active» fixed

Cleaning up the issue queue.

#6

System Message - July 20, 2009 - 20:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.