Before i dive deeper into this vast amount of code - is there a simple way to create relationship links that do not use the Ajax message, and do not redirect to a "Are you sure...?" page?

We would like the user to simply click a link - and have the relationship established/demolished. no fancy ajax, no confirmation pages ;)

If there is no simple pre-built way for this, i'll add some menu links and custom functions to replicate the functionality but without the confirmation.

I thought before i dive into that i should ask - is there a simple way to do this?

Thanks!

CommentFileSizeAuthor
#15 ur_no_confirm.zip2.16 KBliquidcms
#13 ur_no_confirm.zip1.95 KBliquidcms

Comments

alex.k’s picture

There is no way without a confirmation dialog. You need to implement form_alter to take out the confirmation.

henrijs.seso’s picture

This could be added to module as fix.

I dived into module and saw few things that could be improved, this being one. Relationship object could benefit from few more settings, like Link text, which could be different for each RTID, also skip confirmation form could be cool checkbox. I am building a rather large project and could contribute patches along the way, but Ill open new issue for that.

toemaz’s picture

@LavaMeTender

Have you gotten around this? Did you implement hook_form_alter to avoid the confirmation dialog?

henrijs.seso’s picture

yes, I did.

following went to custom module (sorry for debug lines)

function MODULENAME_return_ur($view_result_uid) {
//	dsm($view_result_uid);
	global $user;
//	global $relationships;

	$friend_param = array(
		'between' => array($user->uid, $view_result_uid),
		'rtid' => 1,
	);
	$friend = user_relationships_load($friend_param, $options = array(), $reset = FALSE);

	$follow_param = array(
		'between' => array($user->uid, $view_result_uid),
		'rtid' => 3,
		'requester_id' => $user->uid,
	);
	$follow = user_relationships_load($follow_param, $options = array(), $reset = FALSE);

	$results = array();
	if ($friend) {
		foreach ($friend as $relationship) {
			//dsm($relationship);
			if ($relationship->approved) {
				$results[] = '<span class="relationships friend">Friend' . theme('user_relationships_remove_link', $user->uid, $relationship->rid) . '</span>';
			}
			else {
				if ($relationship->requester_id == $user->uid) {
					$results[] = '<span class="relationships pending">Friend request sent' . theme('user_relationships_pending_request_cancel_link', $user->uid, $relationship->rid) . '</span>';
				}
				else {
					$results[] = '<span class="relationships pending">Friend request received' . theme('user_relationships_pending_request_approve_link', $user->uid, $relationship->rid) . theme('user_relationships_pending_request_disapprove_link', $user->uid, $relationship->rid) . '</span>';
				}
			}
		}
	} else {
		$relate_to = user_load($view_result_uid);
		$relationship_type = user_relationships_type_load(1);
		$results[] = theme('user_relationships_request_relationship_direct_link', $relate_to, $relationship_type);
	}
	if ($follow) {
		foreach ($follow as $relationship) {
			$results[] = theme('user_relationships_remove_link', $user->uid, $relationship->rid);
		}
	} else {
		$relate_to = user_load($view_result_uid);
		$relationship_type = user_relationships_type_load(3);
		$results[] = theme('user_relationships_request_relationship_direct_link', $relate_to, $relationship_type);
	}

	return implode('', $results);
}

function MODULENAME_menu_alter(&$items) {
  $items['relationship/%user/request/%'] = array(
    'title'             => 'Create a relationship',
    'type'              => MENU_CALLBACK,
    'page callback'     => 'MODULENAME_custom_ur_request_callback',
    'page arguments'    => array(1, 3),
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
  );
	$items['user/%user/relationships/%user_relationships/remove'] = array(
		'title'             => 'Remove relationship',
		'type'              => MENU_CALLBACK,
		'page callback'     => 'MODULENAME_custom_ur_remove_callback',
		'page arguments'    => array(1, 3),
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
	);
	$items["user/%user/relationships/requested/%user_relationships/cancel"] = array(
	  'title'             => 'Approve Relationship',
	  'type'              => MENU_CALLBACK,
	  'page callback'     => 'MODULENAME_custom_ur_cancel_callback',
	  'page arguments'    => array('cancel', 1, 4),
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
	);

}

function MODULENAME_custom_ur_request_callback($requestee, $rtid) {
	global $user;
	user_relationships_request_relationship($user, $requestee, $rtid);
	drupal_goto();
}
function MODULENAME_custom_ur_cancel_callback($op, $deleted_by, $relationship) {
	//dsm($op);
	//dsm($deleted_by);
	//dsm($relationship);
	user_relationships_delete_relationship($relationship, $deleted_by, $op);
	drupal_goto();
}
function MODULENAME_custom_ur_remove_callback($deleted_by, $relationship) {
	//dsm($deleted_by);
	//dsm($relationship);
	$op = 'remove';
	//global $user;
	user_relationships_delete_relationship($relationship, $deleted_by, $op);
	drupal_goto();
}

and following into themes template.php

/**
 * Create a direct relationship link
 */
function THEMENAME_user_relationships_request_relationship_direct_link($relate_to, $relationship_type) {
	$link_text = '';
	if ($relationship_type->rtid == 1) {
		$link_text = 'Add as friend';
	}
	elseif ($relationship_type->rtid == 3) {
		$link_text = 'Follow';
	}

  return l(
    $link_text,
    'relationship/' . $relate_to->uid . '/request/' . $relationship_type->rtid,
    array(
      'query' => drupal_get_destination(),
      'html'  => TRUE,
      /*'attributes' => array('class' => 'user_relationships_popup_link'),*/
    )
  );
}

/**
 * Remove relationship link
 */
function THEMENAME_user_relationships_remove_link($uid, $rid) {

	$relationship_type = user_relationships_load($param = array('rid' => $rid), $options = array(), $reset = FALSE);

	$link_text = '';
	if ($relationship_type[$rid]->rtid == 1) {
		$link_text = 'Remove from friends';
	}
	elseif ($relationship_type[$rid]->rtid == 3) {
		$link_text = 'Unfollow';
	}

	  return l(
    $link_text,
    "user/{$uid}/relationships/{$rid}/remove",
    array(
      'title' => array('title' => $link_text),
      'query' => drupal_get_destination(),
      /*'attributes' => array('class' => 'user_relationships_popup_link'),*/
    )
  );
}

Again sorry for code quality and commented lines, but its just what I had to get functionality for my particular case. Havnt looked at this for a while, but it worked. To rest is to add this line in template .tpl or block print MODULENAME_return_ur($uid); where $uid is user ID of other user, not active user and links and statuses will be printed. Please see if any of this helps and if you do manage to improve code, at least paste it here, maybe we can figure out something togather. BTW there are 2 relationships - Friend and Follower in my setup.

toemaz’s picture

Thanks a lot for this fast reply and sharing the code LavaMeTender. It seems we need a similar 'solution' since I wanted followers to start with and perhaps friends later on. I'll share back my code once I'm finished.

mrf’s picture

Status: Active » Postponed

I am postponing any 6.x feature requests that don't have a current applicable patch to help sort the large list of open features.

Please feel free to set to 'needs review' once a patch is included.

lildragon’s picture

Hi, is there any development for this? a simple follow without confirmation is pretty standard these days, i wonder if there is an easy way around it. thanks!

toemaz’s picture

@lildragon no development from my side. I decided to go with the flag module instead. To much overhead with the UR module.

mrf’s picture

Title: Using links with no ajax and no confirmation... ? » Setting to disable confirmation dialog when requesting a relationship
Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue tags: +Novice

This wouldn't be that difficult to implement, but I'd rather this be a admin setting than the default. The most difficult part is separating this from the other concept of approval in the UI.

I'm tagging this as a novice issue, for anyone looking to jump into contributing to UR this would be a good place to start.

lildragon’s picture

thanks for the reply. Yes, I switched to flag as well..

anybody’s picture

Issue summary: View changes

As stated out in #7 this feature is still relevant, +1 for that!

liquidcms’s picture

Been poking around with this for a while and a few comments:

1. seems like a pretty obvious addition to this module; unfortunate that it hasn't been added
2. solution posted in #4 does work but a couple issues with it:
a. theme function no longer takes a sequence of passed vars; it requires an associated array, so this:

theme('user_relationships_pending_request_approve_link', $user->uid, $relationship->rid)

becomes this:

theme('user_relationships_remove_link', array('uid' => $user->uid, 'rid' => $relationship->rid))

b. ideally this would still be ajax driven link; having it do a page load sort of defeats the point of this of trying to make this process more streamlined

3. better solution is still to include this in the module itself as an admin configurable option; but project maintainer suggesting this was Novice must have been joking.. lol

Need to discuss with client how committed they are with this module and whether they want me to add this function or possibly do like most here and switch to the Flags module.

liquidcms’s picture

StatusFileSize
new1.95 KB

i continued with work from #4 and created a module for this.

- self contained module so no need for template.php code
- ajaxified links
- this module is not complete and has a few places which are still specific to my use case; but general concepts are there and work (for RTID =2 (Follow), in my case)

There are a lot of options/changes which could be added to this to make it a generic module:

1. link text needs to be pulled from relationship
2. what are ajax links replaced with? i think the generic case is likely to replace with the opposite link, i.e. replace "follow" with "unfollow"; but in my case, and therefore this module, i simply wanted the "Follow" link to be removed and not replaced with anything. Our users would go to their manage relationships page to unfollow.

liquidcms’s picture

here is a better version of my module. It is mostly generic now although there is a little code to rename the link's instead of what is configurable by the UR module.

this version includes replacing friend link with unfriend link and vise versa. It also does an entire row removal from the manage friends page.

since this is ajax the messages spit out by the UR module are "late"; this could pretty easily be fixed and i may get to that later.

liquidcms’s picture

StatusFileSize
new2.16 KB

oops.. and the ZIP

hockey2112’s picture

Thanks for this! Can you please explain how I your custom module would work if you have more than one type of User Relationship, and need to display both types on the page?

garchris’s picture

Thanks for this code. It worked in preventing confirmation dialog when sending a request. Now I'd like to prevent confirmation dialog when accepting/rejecting a relationship request. I know very little php. Any help appreciated

cassien’s picture

Hello!

I'm using this little module and I have a little problem.

I have multiple "subscribe to user" buttons on a same page.

When you press a button, all the buttons are turning to "subscribed".

And I strictly don't know how to solve that ...

Thanks in advance.