Is there a way to do this? having a link in each core profile (user) where people can message them, instead of having to remember their username? Thanks!

Comments

berdir’s picture

That is part of the module since forever yes, and in 6.x-2.x-dev, it is configurable, so you either disabled it or are using content_profile. If the latter, then you need to something similiar as privatemsg is doing in hook_user, $op view: http://blog.worldempire.ch/api/function/privatemsg_user/6-2 for content_profile.

berdir’s picture

Status: Active » Fixed
web506’s picture

I am using core, can I just upgrade from one to the other overwritting or do I have to remove the other one first?

berdir’s picture

No idea what you mean, you don't need to upgrade anything if you are using profile.module.

If the user viewing the page is allowed to write the user to which the profile belongs, then there should be a link to write that user a message, unless you have disabled it at admin/settings/messages.

web506’s picture

Thanks it is working fine now. The only issue I am having is that if I set the contact link on user profiel evrybody has access to it, even people with no permission to use private message, so if they click that link they can send messages.

I am using Panels for the profile page. I was not able to locate a panel that will display this link ( contact this user ) any ideas on how to do it? thanks!

berdir’s picture

Erm.. when you're using panels, then you're *not* using profile.module to display the user profile. And then obviously, it doesn't work out of the box;)

Try the following php code, note that you might need to change $account to the name of profile user variable, panels should tell you how that's named.

      if ($url = privatemsg_get_link(array($account))) {
        return l(t('Contact this user'), $url, array('query' => drupal_get_destination()));
      }
 

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bjsomers’s picture

Version: » 6.x-1.3
Status: Closed (fixed) » Active

Hi,

I'm a total newbie, but would like to put that link on my profile panel. How would I implement that code? When I try to create a custom content pane it just shows the code as text in the block.

Thanks

berdir’s picture

Status: Active » Fixed

Well, you need to tell panels that this is PHP code, probably by using the PHP filter format.

john.campbell-higgens’s picture

Have tried to code above to add a link in a panel but it gives a link of:

http://drupaltest/messages/new/?destination=user/10

Which just presents the blank new private message. if I remove the ?destination=user/ section so you have

http://drupaltest/messages/new/10

This works, but not sure how to change the code, can anyone help.

pauljb’s picture

I checked the "Use context keywords" in Panels and used the following Full HTML format:

< a href="../messages/new/%user:uid" title="Send Private Message">Send private message

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

calefilm’s picture

I have a separate issue over here: http://drupal.org/node/1108544 that is a question about how to create a Send Message tab on User Profile. This issue is somewhat related but different. I would appreciate questions to both, if anyone has the time.

Regarding this thread and adding a simple link, I tried the code in #6

<?php
      if ($url = privatemsg_get_link(array($account))) {
        return l(t('Contact this user'), $url, array('query' => drupal_get_destination()));
      }
?>

and when I click the link "Contact this user" i get: /messages/new/?destination=user%2F16%2Fmessage
(by the way, I changed "privatemsg" to "messages")

note that you might need to change $account to the name of profile user variable

Where does panels tell me what variable to use?

I get the Write New Message page but the To: is empty

16 is the uid I'm trying to contact. So it is coming up, just in the wrong place.


My Steps
What I've done is add a Tab on the user/%uid profile page. It's a separate panel page: user/%uid/send-message with a Menu Tab: Send Message

Result A:
Ideally, I'd like to have a Tab on profile page, "Send Message" that links to: /messages/new/16
http://drupal.org/node/1108544

Result B:
But couldn't figure out how to add a tab that links to /messages/new/16 so I simply added new content with php code inside it. Now, a user clicks, "Send Message" Tab (which is a panel page), and sees the link below it, "Contact this user"

cwithout’s picture

To anyone happening across this needing to accomplish the same thing, the code in #6 is not complete. If the $account variable isn't defined, you'll get a link to exactly what people are getting "/messages/new/?destination=user%2F16%2Fmessage".

That's because $account needs to have the account object for the user you want to be contacted when the link is clicked.

Here's one way you can get the user object. (This will work only on the user pages (/user/#).)

if (arg(0) == 'user' && is_numeric(arg(1)) ) {
  $url = privatemsg_get_link( array( user_load(arg(1)) ) );
  $content = l(t('Contact this user'), $url, array('query' => drupal_get_destination()));
}
TelFiRE’s picture

#11 would seem to be a simpler and better approach, storing PHP in the database is not really a good practice.

It would be really nice to just add a panels display item which had this link. Can't imagine it would be super tough.

ragavendra_bn’s picture

Issue summary: View changes

I am using display suite and used the below php or html using the custom field. It now works like a charm.

<?php
echo '<a href="../messages/new/[profile2:user:uid]">Message me<br>';
?>