I redid the user_relationships_request function. When requesting a relationship, when there's only one relationship type available it's nice just to set that relationship directly without having to choose type of relationship and then pressing the submit button. Thus I borrowed the submit function and put it in the function. It checks if there's only relationship and if so just submits the info and redirects back to the requestee's page. Now it incorporates validation but I'm not sure its completely right which is kind of ugly


/**
 * Request a new relationship with another user
*/
function user_relationships_request($requestee_id) {
  global $user;
  $requester = user_load(array('uid' => $user->uid));
  $requestee = user_load(array('uid' => $requestee_id));

  if (empty($requestee->name)) {
    drupal_set_message(user_relationships_get_message('non_existant_user'));
  }
  else if (!user_access('can have relationship', $requestee)) {
    drupal_set_message(user_relationships_get_message('not_accepting_requests'));
  }
  else if ($user->uid == $requestee_id) {
    drupal_set_message(user_relationships_get_message('self_request'));
  }
  else {
    $form = user_relationships_request_form($requester, $requestee);
    if (!$form['rtid']['#options']) {
      drupal_set_message(user_relationships_get_message('too_many_relationships'), 'error');
    }
    else if ( sizeof( $relations = user_relationships_types_load() ) < 2 ) {
		foreach( $relations AS $relation ){ $rtid = $relation->rtid; }
		
		  if (user_access('can have relationship', $requestee)) {
		    if ($current_relationships = user_relationships_load(array('between' => array($requester->uid, $user->uid)))) {
		      drupal_set_message(user_relationships_get_message('too_many_relationships'), 'error');
		      drupal_goto();
		    }
		  }
		  else {
		    drupal_set_message(user_relationships_get_message('not_accepting_requests'));
		    drupal_goto();
		  }	        	          

		  $relationship_type  = user_relationships_type_load(array('rtid' => $rtid));		
		  $relationship = user_relationships_request_relationship($user->uid, $requestee_id, $relationship_type);
		
		  if ($relationship === FALSE) {
		    drupal_set_message(user_relationships_get_message('unknown_error', $relationship));
		  }
		
		  $relationship->requester = $requester;
		  $relationship->requestee = $requestee;
		  $relationship->type = $relationship_type;
		
		  drupal_set_message(user_relationships_get_message(($relationship->approved ? 'pre_approved' : 'submitted'), $relationship));
		
		  drupal_goto(drupal_get_path_alias('user/'.$form_values['requestee']));	    
	    }  
    else {
      $form = confirm_form(
        $form,
        t('How do you relate to %name?', array('%name' => $requestee->name)),
        "user/$requestee->uid",
        '',
        t('Create'), t('Cancel'),
        'user_relationships_request_confirm'
      );

      return $form;
    }
  }

  drupal_goto();
}


Comments

toemaz’s picture

This plugin could help you out: http://drupal.org/node/246397
It's not officially added to the UR module but it nicely fits into the module.

Let me know if it works out for you so I might further improve the plugin

reed.richards’s picture

Nice idea! However the community site I was working on is now out, and out of my hands. :)

alex.k’s picture

Status: Needs review » Closed (duplicate)

Please refer to the link @toemaz posted, this is now implemented.