Link to "New Message" from profile page

McGo - July 22, 2008 - 17:07
Project:Privatemsg
Version:HEAD
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:patch (code needs work)
Description

I want to create a link that says "Send this user a new message". So I have to call a url like messages/private/new/4711 where 4711 is the uid of the receipient. Currently this is not possible.

#1

litwol - July 22, 2008 - 17:46
Priority:normal» critical
Assigned to:Anonymous» litwol

#2

nbz - July 25, 2008 - 15:59
Status:patch (code needs work)» patch (code needs review)

Not sure about the best way to do this, but I do have a working version:

In the menu code add:

<?php
  $items
['user/%user/message'] = array(
   
'title' => 'Send Message',
   
'page callback' => 'drupal_get_form',
   
'page arguments' => array('privatemsg_new'),
   
'access arguments' => array('write privatemsg'),
   
'type' => MENU_LOCAL_TASK,
  );
?>

and then in privatemsg_new replace

<?php
$recipient
= '';
?>

with

<?php
 
if (arg(1) == 'new') {
   
$recipient = '';
  }
  else {
  
$user = user_load(arg(1));
  
$recipient = $user->name;
  }
?>

I have not added as a patch because it is not pretty. But it does work, but a little differently from the asked for solution:

1. a user's profile page will contain a tab called "Send Message". This goes to user/uid/message, where the recipient is autofilled in.

2. However, this also adds a tab to a user's own page too, so a user can itself a message this way. Some may like this, but I consider it a bug.

#3

nbz - July 25, 2008 - 16:01
Title:Link to "New Message"» Link to "New Message" from profile page

#4

litwol - July 25, 2008 - 22:46
Priority:critical» normal
Assigned to:litwol» Anonymous
Status:patch (code needs review)» fixed

Commited to HEAD

#5

nbz - July 27, 2008 - 17:14
Status:fixed» patch (code needs work)

This does not have any access checks.

Viewing the profile page shows the link to send a new message even if the user does not have permission (only after clicking the link will the user realise the lack of permission - with the access denied message.)

 
 

Drupal is a registered trademark of Dries Buytaert.