re: https://www.drupal.org/node/1549540#comment-6625338

What I need is only the intended recipient's and the sender's user picture to display (participants). Never mine.

Use case:
Imagine a dating site's inbox/sent folder. You never see your own user picture whether you start the thread or not. When I send a new message to a recipient I need their user picture to be displayed in the /messages. Also, when I receive a new message from anyone I need their user picture displayed in the /messages/sent.

The column "Participants" already prints what i'm looking for but as a link. I need the participant's user picture and not their username. However, I don't user the participants column since in my use case their is always just one participant. So, I'm trying to get this to work in place of the referenced link above.

Hope that makes sense.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

System Lord’s picture

Or, if simpler, I can remove the custom code in the referenced link above, move "Participants" column in front of Subject column, then modify code to use "user picture" instead of "account link" for "Participants". So, it would display user picture first followed by subject then messages then timestamp.

I'm pretty sure i can make the correct changes in column order by changing weights. I do not know the coding for changing account link to user picture.

I appreciate any assistance.

jweirather’s picture

Thanks for your notes.

Following this. To suit my own needs, I'm going to be modifying the code we discussed in: https://www.drupal.org/node/1549540.

I'll see if I can't (50/50) make it generic enough for others to adapt for their own needs. I'll post back if/when that happens. At least a week away at this point.

JPW

System Lord’s picture

Thanks jweirather! I look forward to it. I can help test anytime along the way.

System Lord’s picture

Hi jweirather. Any progress?

jweirather’s picture

Haven't looked at it yet.Wading through a commerce project ATM, but hope to return to this in a few days. Sorry for delay.

System Lord’s picture

How'bout a few Jackson's to get this baby done?

jweirather’s picture

hahahaha. Have been sidetracked on another project. Will look at this today. I just did some sanity check searching, came across this: https://www.drupal.org/node/1573000. Haven't investigated yet, but if it offers views integration, it may be a great starting point. I'll try to post back later today with an update.

System Lord’s picture

Hi jweirather, I read through thread. I didn't see anything that addressed what I need "Participant user picture instead of author's user picture." I don't think views or their patch is designed to give me what I want. I didn't test it, but I also didn't really want to create a view for this. I am, however, open to it as a last resort.

jweirather’s picture

Noted. I'm working through some of this now. For me personally, I'd rather have the views integration, but this patch is for a privatemsg version that I don't think I can use (I don't remember why). So I'm still looking at just getting the users/pictures as discussed.

Out of curiosity, is there a technical reason you want to avoid views for this? Not trying to advocate one way or another, just wondering if there's something I'm not aware of (performance, etc)...

Will be in touch.

System Lord’s picture

Hi jweirather, I really don't have opposition to using views integration. In my use case I just don't want the logged in user's picture (the user that is viewing their own pm messages and list) displayed in any pm messages or pm lists. If a view can be designed to do this then I'm ok with it. I was only concerned about keeping the necessary code minimized. i.e., a couple lines in a patch vs. a complete view. Too picky?

Thinking more about it, if using views instead of a patch I could get more flexibility in designing my own expression of a message lists then that would be nice.

jweirather’s picture

@systemlord: here is a hackity-hack-hack for my privatemsg module (7.x-1.4) that appears to do what you want. In privatemsg.module, locate the function privatemsg_recipient_format(). In 7.x-1.4 that's at line 2657. In 2.x it looks like it's at 2730. Find the line that reads:

return theme($type['format'], array('recipient' => $recipient, 'options' => $options));

and change it to say:

return theme('user_picture', array('account' => $recipient)) . theme($type['format'], array('recipient' => $recipient, 'options' => $options));

It should be pretty self explanatory. I didn't create a patch because I can't test it on my installed version and I don't want to offer untested patches -- though I'm apparently okay with hacking modules. If I upgrade to 2.x I will try to submit said patch, along with testing the views integration, which I think would be a better long term solution, especially for dashboards, etc.

Please report back if this does the trick for you. HTH

jweirather’s picture

As an aside, I now believe you can use this code:

theme('user_picture', array('account' => $user_object))

to generate a user avatar wherever you want it. You just need to make sure that the user_object is properly initialized/named. In this case, it the user_object was already available in that function, passed in as the argument $recipient. That's my understanding anyway.

System Lord’s picture

A hack is fine with me. I'll be putting it into a custom module eventually. I'll test these in about about an hour and get back with you.

System Lord’s picture

I tried your second suggestion....

function privatemsg_recipient_format($recipient, $options = array()) {
  if (!isset($recipient->type)) {
    $recipient->type = 'user';
    $recipient->recipient = $recipient->uid;
  }
  $type = privatemsg_recipient_get_type($recipient->type);
  if (isset($type['format'])) {
    theme('user_picture', array('account' => $user_object))
  }
  return NULL;
}

Parse error: syntax error, unexpected '}' in /home/mysite/public_html/site/sites/all/modules/privatemsg/privatemsg.module on line 2737

Your hack is on line 2736.

jweirather’s picture

Missing semi colon at the end of the "theme" line.

jweirather’s picture

Also, you need a return statement, and where it says "$user_object" it should say "$recipient" instead. Like so:

function privatemsg_recipient_format($recipient, $options = array()) {
  if (!isset($recipient->type)) {
    $recipient->type = 'user';
    $recipient->recipient = $recipient->uid;
  }
  $type = privatemsg_recipient_get_type($recipient->type);
  if (isset($type['format'])) {
    return theme('user_picture', array('account' => $recipient));
  }
  return NULL;
}

I'd used the "$user_object" as an example variable, that you need to change according to what is available in context. In this case, the function is receiving the user object as an argument called "$recipient", shown in the first line:

function privatemsg_recipient_format($recipient, $options = array()) {

As a result, you need to refer to the object variable by that name.

System Lord’s picture

FileSize
236.11 KB

Here's what I did to get what you see in the attachment. I viewed a user's profile and click the link to send that user a PM.

I copied your function above and replaced what was already in there.

I hope I'm doing it correctly.

jweirather’s picture

I think I see what's happening. We need to add a check to make sure we're looking at the "messages" list, otherwise it should be default behavior (because I have no clue what other features may call this function).

Can you confirm that it's working as expected on the messages list, eg: inbox?

I'll work on an if statement.

jweirather’s picture

Try replacing your function with this one. I added an if statement to check if you're on the page called "messages", in which case you'll get the avatar. If you're not on that page, it should fall back to default behavior. You can change the page name "messages" to be whatever your actual inbox page name is. If you have multiple pages where you want to see the avatar, you'll need to amend the if statement to include those page names. eg: if ($_GET['q'] == 'messages' || $_GET['q'] == 'otherpage') {

function privatemsg_recipient_format($recipient, $options = array()) {
  if (!isset($recipient->type)) {
    $recipient->type = 'user';
    $recipient->recipient = $recipient->uid;
  }
  $type = privatemsg_recipient_get_type($recipient->type);
  if (isset($type['format'])) {
    if ($_GET['q'] == 'messages') {
      return theme('user_picture', array('account' => $recipient));
    }
    else {
      return theme($type['format'], array('recipient' => $recipient, 'options' => $options));
    }
  }
  return NULL;
}
System Lord’s picture

Sorry, I did check that and forgot to mention it. Looking at my inbox with existing messages already there it has not made a difference. I'm still seeing my user picture. However, I was thinking your change wouldn't affect message already existing which is why I was trying to start a new thread which is what you see in my previous attachment. So, I can't start a new thread to test it completely with a new thread.

jweirather’s picture

This code would be adding the avatar to the recipient's list, not replacing the "author" avatar on the subject line. Sorry I wasn't clear about that, I was going from your comment #1. It's working well for me right now, showing the avatar in the messages list on the "messages" page, but falling back to default behavior on other pages...

jweirather’s picture

It's built on the fly, so it should work on old messages too (it is for me). Don't forget to clear cache, though you shouldn't really need to.

System Lord’s picture

Ok, just tested that last function you provided. I can't see that anything changed. My inbox still shows my picture and not the recipients. The same with the Sent folder/tab....only my picture. I was able to start a new thread, tho, but no difference.

System Lord’s picture

Ahh, ok, well I turned off recipients column (oops), thats why I'm not seeing what you are. I'll turn it back on and check, but are you saying that your changes makes it so that the sender and recipients picutres are displayed at the same time then?

System Lord’s picture

Sorry, I didn't realize you were working on the suggestion in #1.

System Lord’s picture

It will take me a few minutes to restructure my config to suit #1 option. I'll get back asap.

System Lord’s picture

After turning participants back on I can see the precipients picture now. So, excellent there!. I'll jsut have to play with it to get author image out of the lists (inbox and sent). brb

jweirather’s picture

This is what I'm seeing, in unstyled, rough draft format, of course. My understanding is you'll want to back out the original changes from the previous thread.

System Lord’s picture

Yep, dizzler, that's what I see now as well :)

jweirather’s picture

It's Dizzle, actually, that was a typo :)

Is this working okay for you? I'll be looking at the views integration in a couple of weeks, but wanted to close out this thread.

System Lord’s picture

Yeah dizzle, this is working just the way I wanted. Thank very much for the code!

jweirather’s picture

Status: Active » Closed (fixed)

@System Lord: No worries, HTH.

System Lord’s picture

I wonder if the title of this issue should be changed to more accurately reflect what your code does. Something like: "Participant avatar/user_picture in place of participant username in PM lists"

jweirather’s picture

Title: Participant user picture instead of author's user picture » Participant avatar/user_picture in place of participant username in PM lists

@System Lord: Good call. Edited and reposted for posterity.

@Future readers: If you're looking to include the user picture/avatar in the participants list, you should be able to piece together a working, temporary solution using comments:

#11 to locate the function in question, *adds* photos to recipient list wherever the recipient's list is used, which may be problematic in some uses, such as composing new messages
#19 *replaces* the name with a user avatar, adds an if statement to only show the avatar on the "/messages" page, so that default behaviors continue to work on other pages.

It is highly recommended that you move these into your own module, which is beyond the scope of this thread.

System Lord’s picture

jweirather, please look at my posted issue: https://www.drupal.org/node/2460577#comment-9949669

Could that be related to this thread? Or maybe you some input to the issue.

System Lord’s picture

Seeing another issue. If I have a dozen messages in my list and I preform any action Delete, Mark as read, or Mark as unread, all user pictures disappear with their username put in its place. When I refresh the page all the pictures return.

SL

jweirather’s picture

@System Lord-

I'm pretty far away from private messages at the moment, but will be returning to it in a few weeks. I'll be happy to see what I can do then. In the meantime, please post back if you make any progress elsewhere.

System Lord’s picture

Thanks, jweirather. In the interim I'm trying to completely remove the ajax process. I believe if I can force the page to be reloaded it will not affect the user pictures. Ultimately i do want the ajax process, but having the page reload is fine as well.

See also: https://www.drupal.org/node/2495247

System Lord’s picture

Never mind that link in #38. I got hog-tied.

System Lord’s picture

I've tried some things (work-arounds), but got no where. I'll wait for you :)

System Lord’s picture

No pressure. Just want you to know I'm still interested in having #36 looked at.

Have a great 4th!