0

In my project, I have user relationship module installed. I created a view of online users. I then tried to include a link to enable users "add friends or create relationship" in the view by adding the following code

 global $user;
  $opt = '';
  $requestee_id = $row->uid;
  $requester_id = $user->uid;
  if (user_is_logged_in()) {
    if ($requestee_id != $requester_id) {
      //for friend request button
      $relationships = user_relationships_load(array('between' => array($requester_id, $requestee_id)));
      if (empty($relationships)) {
        $opt = l(t('Add Friend') , "relationship/$requestee_id/request/1", array('html' => TRUE, 'absolute' => TRUE, 'query' => array('destination' => 'user/' . $requestee_id), 'attributes' => array('class' => array('ur-link add-friend-btn user_relationships_popup_link'))));
      }
      else {
        foreach ($relationships as $relationship) {
          if ($relationship->approved == 1 && user_relationships_ui_check_access('view', NULL, $relationship)) {
            $opt = t('<span class="already-frnd">Friends</span>');
          }
        }
      }
    }
  }
  print $opt;  

When I try to create a relationship, i am informed that "this user does not exist". Please what could I be doing wrong.

P.S: I have 2 relationships on my site. Thanks in anticipation.

1 Answer 1

0

I found out this could be done without writing custom code.

In the view:

  1. I added a field, User:uid.

  2. I unchecked "create a label" and "link this field to its user"

  3. Using Rewrite results, i checked Rewrite the output of this field and input "Add as friend".

  4. I checked the "Output this field as a link" and then added the path www.example.com/relationship/[uid]request/1?destination=user/[uid]

That solved the issue.

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.