1

Use case: When a user is viewing a private message (from the privatemsg module), I would like to display the following:

  • a picture field from the user's profile (not the user's profile picture)
  • a link to flag the user (to report potential abuse)

Senders should see values for recipients and recipients should see values for senders. How might I go about implementing this?

What I've found out so far:

Out of the box, privatemsg cannot be overriden by Panels. The Panelizer project is not able to add panes on, either. There is a Privatemsg Panels sandbox project for which some work has been done but I need a more mainstream, maintainable solution.

Work on the D7 version of Privatemsg Views is currently stalled.

1
  • bounty! :o You rock!
    – emc
    Apr 4, 2013 at 20:36

2 Answers 2

2
+50

I've just implemented the Privatemsg Panels plugin with the D7 Patch through the pm_existing_pages plugin and it's working quite well! Here's how it all goes down for Drupal 7:

  • Grab the master branch of the privatemsg_panels module and upload to your modules directory
  • Patch Manager is super handy - install it and run the panels_privatemsg7.patch file to upgrade the module to a 7.x branch (or patch by hand or drush or eclipse etc)
  • Optional: Install PM Existing Pages and add override the default /messages/ path with a new panel. Of course you could create a new panels page just as easily.
  • Add content to your panel - Privatemsg should be a menu item now: enter image description here
  • Create a nice little custom link block from the instructions over here - might be useful for your particular view!
  • Optional: override privatemsg-view.tpl.php for a more custom layout. I haven't quite got this far, will try to remember to update this when I give it a shot.

Edit - Adding info!

  • Overriding privatemsg-view.tpl.php works great, just remember to clear the cache after you add the file to your theme folder.
  • Take a look at the Privatemsg Theming Documentation. All of the functions that start with phptemplate_ can be overridden by your own theme. Example: drop this into your template.php file

    function YOURTHEMENAME_privatemsg_list_field__participants($variables) {
        $thread = $variables['thread'];
        $field = array();
    
        if ($thread['has_tokens']) {
            $message = privatemsg_message_load($thread['thread_id']);
        }
        if (!isset($message)) {
            $message = privatemsg_message_load($thread['thread_id']);
        }
    
        $participants = _privatemsg_generate_user_array($thread['participants'], -4);
    
        $field['data'] = theme('user_picture', array('account' => $message->author));
        $field['data'] .= '<div class="user-name">'. _privatemsg_format_participants($participants, 3, TRUE).'</div>';
    
        $field['class'] = 'privatemsg-list-participants';
    
        return $field;
    }
    

    This will add a user picture to the recipients field! AWESOME! Just remember that each overridden fuction expects to have 3 things returned: a field, a header theme pattern, and a field theme pattern - the documentation explains it better than I can ;)

  • The functions at the Privatemsg Theming Documentation starting with theme_ can be overridden using a function YOURTHEMENAME_form_alter() hook. If you add this function to your template.php, drop dsm($form_id); dsm($form); in to get a better idea of exactly what form you're working with.
  • Looking to change column order around? It's easier than you might think - check out the drag-and-drop column order at /admin/config/messaging/privatemsg

There has been a bit of discussion about how to add custom columns to the output but I'm not there yet.. I'll have to point you at the Privatemsg Issue Queue for that one.

Good luck!

2
  • I recently came across the need to display the user picture in the inbox and sent folder. Your code does display the user picture, but it appears to display the picture of the last user who responded. Often, this may end up being the currently logged-in user, which is weird... it should always display the other user's picture. This post (drupal.org/node/1549540#comment-7273558) removes the current user from the display, but then if the recipient has never replied then no picture shows up. Any ideas on how to make it so the recipient's pic is always displayed?
    – hockey2112
    Jan 7, 2017 at 20:07
  • @hockey2112 perhaps extra logic around the user picture in the snippet above can do the trick. What are the contents of $thread['participants'] and $participants?
    – emc
    Jan 7, 2017 at 23:39
1

Yeah, Privatemsg doesn't really integrate with the world of Views and Panels.

However, we do have enough hooks and templates to implement this. You can use privatemsg_message_view_alter() to add additional things like a report link (look at pm_block_user.module for an example of that) to the message body. And you can override the privatemsg-view.tpl.php template file to customize the whole thing.

1
  • Work on the D7 version of Privatemsg views is occuring here: drupal.org/node/1573000. There are patches which passed validation.
    – Druvision
    Nov 5, 2013 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.