Is it possible to create a link to send private message to CURRENT USER in the node (to the author of the node content to be more precise). I'm using the Privatemsg module. I was trying to do this with the Display suite dynamic fields, but I am not able.
I found that the Privatemsg module comes with an option to "Display link on the selected content types. So, I have the "contact current member link" right in the content type, but it shows only for logged in users.
Is there any configuration or hook that I can implement to show the same link to anonymous user?
This is the code that shows the link.
function privatemsg_node_view($node, $view_mode) {
$types = array_filter(variable_get('privatemsg_link_node_types', array()));
$url = privatemsg_get_link(user_load($node->uid));
if (in_array($node->type, $types) && !empty($url) && ($view_mode == 'full' || (variable_get('privatemsg_display_on_teaser', 1) && $view_mode == 'teaser'))) {
$node->content['links']['#links']['privatemsg_link'] = array(
'title' => t('Contact member'),
'href' => $url . '/' . t('Message regarding @node', array('@node' => $node->title)),
'query' => drupal_get_destination(),
'attributes' => array('class' => 'button radius privatemsg-send-link privatemsg-send-link-node'),
);
}
}
To make it clearer, I don't want anonymous user to send messages. What I want is just a link to log in for anonymous users. Expressing it with pseudo-code...
global $user;
if (isset($user->roles[1])) {
// Do not show button to Anonymous user and show something else or a button to log in (THE CODE FOR LOG IN)
echo "something else";
}
else {
// Show button to logged in user (the code of "Send author a message" button)
}