[support] support Digest, Vol 56, Issue 13

Antoine Spadoni antoine.spadoni at gmail.com
Fri Aug 10 15:00:57 UTC 2007


Hi William and Stefan,

Just tested the function, it works fine. I now get the node title within the
Subject of the message.

Thank you for your help and advice regarding the hook_form_alter,

Antoine


Message: 2
> Date: Fri, 10 Aug 2007 10:46:42 -0400
> From: "William Smith" <william.darren at gmail.com>
> Subject: Re: [support] Help: Privatemsg Module
> To: support at drupal.org
> Message-ID:
>         <74630ca20708100746x651e9494r29c77346616895a at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Antoine -
>
> Admittedly I only looked this over quickly, so apologies if I've
> misunderstood what you are trying to do, but think you would want to do
> something like the following in privatemsg_new_form():
>
> $node = node_load(arg(3));
>
> $form['header']['subject'] = array(
>   '#type' => 'textfield',
>   '#title' => t('Subject');
>   '#default_value' => $node->title,
>   '#size' => 50,
>   '#maxlength' => 65,
> );
>
> Also, if privatemsg_new_form() is a function inside privatemsg.module,
> rather then editing it directly, you may want to look into using
> hook_form_alter to modify the form externally so that you don't have to
> hack
> the module.
>
> William
>
> On 8/10/07, Antoine Spadoni <antoine.spadoni at gmail.com> wrote:
> >
> > Hi,
> >
> > I am looking to do a slight modification in my Drupal installation
> within
> > the *Private*msg module.
> >
> > Below my nodes, I added a contact author link and now I want to display
> > the Title of the node within the Subject Field of the message.
> >
> > So first, I added the nid of the node in the URL of the message in order
> > to be able to retrieve the title of the node:
> > /**
> >  * Implementation of hook_link().
> >  */
> > function privatemsg_link($type, $node = NULL, $teaser = FALSE) {
> >   global $user;
> >   static $access = array();
> >   $links = array();
> >   $nid = $node->nid;
> >   $uid = $node->uid;
> >   if ($type == 'comment' && $node->nid) {
> >     $node = node_load($node->nid);
> >   }
> >   if (user_access('access private messages') && in_array($teaser ?
> > 'teaser' : $type, variable_get('privatemsg_link_'. $node->type,
> array())) &&
> > $uid != $user->uid && $user->privatemsg_allow) {
> >     if (!isset($access[$uid])) {
> >       $author = user_load(array('uid' => $uid));
> >       $access[$uid] = user_access('access private messages', $author) &&
> > $author->uid && $author->privatemsg_allow;
> >     }
> >     if ($access[$uid]) {
> >       $links['privatemsg_write_to_author'] = array(
> >         'title' => t('Write to seller'),
> >         'href' => 'privatemsg/new/'.$uid.'/'. $nid,
> >       );
> >     }
> >   }
> >   return $links;
> > }
> >
> > But now I am unable to manage to modify properly this function and
> display
> > the Title of the node within the Subject Field of the message:
> > /**
> >  * Provides a form to write a private message.
> >  */
> > function privatemsg_new_form() {
> >   global $user;
> >   $message = 0;
> >
> >   $op = arg(1);
> >   if ($op == 'reply') {
> >     $message = arg(2);
> >   }
> >   else if (($uid = arg(2)) && ($msg->recipient =
> > db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid)))) {
> >     $message = $msg;
> >   }
> >
> >   if ($message && !is_object($message)) {
> >     // This is a reply to another message
> >     $message = db_fetch_object(db_query('SELECT thread, subject,
> message,
> > u.name AS recipient FROM {privatemsg} p INNER JOIN {users} u ON u.uid =
> > p.author WHERE id = %d AND recipient = %d', $message, $user->uid));
> >
> >     if (!stristr($message->subject, t('Re:'))) {
> >       $message->subject = t('Re:') .' '. $message->subject;
> >     }
> >
> >     // quoting; [quote] if default input format uses bbcode or quote,
> else
> > > quoting
> >     foreach
> > (filter_list_format(filter_resolve_format(FILTER_FORMAT_DEFAULT)) as
> > $filter) {
> >       if ($filter->module == 'bbcode' || $filter->module == 'quote') {
> >         $bbcode = TRUE;
> >         break;
> >       }
> >     }
> >     if (isset($bbcode)) {
> >       $message->message = "\n\n[quote=". $message->recipient .']'.
> > $message->message .'[/quote]';
> >     }
> >     else {
> >       $message->message = "\n\n\n". str_replace("\n", "\n> ", "\n".
> > $message->message);
> >     }
> >   }
> >
> >   if (isset($_SESSION['recipients'])) {
> >     $recipient = implode(', ', $_SESSION['recipients']);
> >     unset($_SESSION['recipients']);
> >   }
> >
> >
> >   $form = array('preview' => array());
> >
> >   $form['thread'] = array('#type' => 'value', '#value' =>
> > isset($message->thread) ? $message->thread : 0);
> >   $form['header']['#theme'] = 'privatemsg_new_msg_header';
> >   $form['header']['recipient'] = array(
> >     '#type' => 'hidden',
> >     '#title' => t('Purchase'),
> >     '#description' => t('Separate multiple names with commas.'),
> >     '#default_value' => isset($recipient) ? $recipient :
> > $message->recipient,
> >     '#autocomplete_path' => 'privatemsg/autocomplete',
> >     '#size' => 50,
> >     '#maxlength' => 1000,
> >   );
> >
> >   $form['header']['subject'] = array(
> >     '#type' => 'textfield',
> >     '#title' => t('Subject'),
> >     '#default_value' => $message->subject,
> >     '#size' => 50,
> >     '#maxlength' => 64,
> >   );
> >
> >   $form['privatemsgbody'] = array(
> >     '#type' => 'textarea',
> >     '#title' => t('Message'),
> >     '#default_value' => $message->message,
> >     '#cols' => 80,
> >     '#rows' => 6,
> >   );
> >   $form[] = filter_form($message->format);
> >   $form[] = array(
> >     '#type' => 'submit',
> >     '#value' => t('Preview')
> >   );
> >   $form[] = array(
> >     '#type' => 'submit',
> >     '#value' => t('Send private message')
> >   );
> >   $form['#after_build'] = array('_privatemsg_new_preview');
> >
> >   drupal_add_js(drupal_get_path('module', 'privatemsg')
> > .'/privatemsg.js');
> >
> >   return $form;
> > }
> >
> > Any help to get this modification done would be greatly appreciated!
> >
> > Thanks,
> >
> > Antoine
> >
> > --
> > [ Drupal support list | http://lists.drupal.org/ ]
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://lists.drupal.org/pipermail/support/attachments/20070810/3157e97c/attachment-0001.htm
>
> ------------------------------
>
> Message: 3
> Date: Fri, 10 Aug 2007 16:48:07 +0200
> From: Stefan Nagtegaal <drupal-support at robuustdesign.nl>
> Subject: Re: [support] Help: Privatemsg Module
> To: support at drupal.org
> Message-ID: <BF7DDC14-9B1A-424F-995D-9A37399359CE at robuustdesign.nl>
> Content-Type: text/plain; charset="us-ascii"
>
> Test?
>
> Op 10-aug-2007, om 16:46 heeft William Smith het volgende geschreven:
>
> > Antoine -
> >
> > Admittedly I only looked this over quickly, so apologies if I've
> > misunderstood what you are trying to do, but think you would want
> > to do something like the following in privatemsg_new_form():
> >
> > $node = node_load(arg(3));
> >
> > $form['header']['subject'] = array(
> >   '#type' => 'textfield',
> >   '#title' => t('Subject');
> >   '#default_value' => $node->title,
> >   '#size' => 50,
> >   '#maxlength' => 65,
> > );
> >
> > Also, if privatemsg_new_form() is a function inside
> > privatemsg.module, rather then editing it directly, you may want to
> > look into using hook_form_alter to modify the form externally so
> > that you don't have to hack the module.
> >
> > William
> >
> > On 8/10/07, Antoine Spadoni <antoine.spadoni at gmail.com> wrote:
> > Hi,
> >
> > I am looking to do a slight modification in my Drupal installation
> > within the Privatemsg module.
> >
> > Below my nodes, I added a contact author link and now I want to
> > display the Title of the node within the Subject Field of the message.
> >
> > So first, I added the nid of the node in the URL of the message in
> > order to be able to retrieve the title of the node:
> > /**
> >  * Implementation of hook_link().
> >  */
> > function privatemsg_link($type, $node = NULL, $teaser = FALSE) {
> >   global $user;
> >   static $access = array();
> >   $links = array();
> >   $nid = $node->nid;
> >   $uid = $node->uid;
> >   if ($type == 'comment' && $node->nid) {
> >     $node = node_load($node->nid);
> >   }
> >   if (user_access('access private messages') && in_array($teaser ?
> > 'teaser' : $type, variable_get('privatemsg_link_'. $node->type,
> > array())) && $uid != $user->uid && $user->privatemsg_allow) {
> >     if (!isset($access[$uid])) {
> >       $author = user_load(array('uid' => $uid));
> >       $access[$uid] = user_access('access private messages',
> > $author) && $author->uid && $author->privatemsg_allow;
> >     }
> >     if ($access[$uid]) {
> >       $links['privatemsg_write_to_author'] = array(
> >         'title' => t('Write to seller'),
> >         'href' => 'privatemsg/new/'.$uid.'/'. $nid,
> >       );
> >     }
> >   }
> >   return $links;
> > }
> >
> > But now I am unable to manage to modify properly this function and
> > display the Title of the node within the Subject Field of the message:
> > /**
> >  * Provides a form to write a private message.
> >  */
> > function privatemsg_new_form() {
> >   global $user;
> >   $message = 0;
> >
> >   $op = arg(1);
> >   if ($op == 'reply') {
> >     $message = arg(2);
> >   }
> >   else if (($uid = arg(2)) && ($msg->recipient = db_result(db_query
> > ('SELECT name FROM {users} WHERE uid = %d', $uid)))) {
> >     $message = $msg;
> >   }
> >
> >   if ($message && !is_object($message)) {
> >     // This is a reply to another message
> >     $message = db_fetch_object(db_query('SELECT thread, subject,
> > message, u.name AS recipient FROM {privatemsg} p INNER JOIN {users}
> > u ON u.uid = p.author WHERE id = %d AND recipient = %d', $message,
> > $user->uid));
> >
> >     if (!stristr($message->subject, t('Re:'))) {
> >       $message->subject = t('Re:') .' '. $message->subject;
> >     }
> >
> >     // quoting; [quote] if default input format uses bbcode or
> > quote, else > quoting
> >     foreach (filter_list_format(filter_resolve_format
> > (FILTER_FORMAT_DEFAULT)) as $filter) {
> >       if ($filter->module == 'bbcode' || $filter->module == 'quote') {
> >         $bbcode = TRUE;
> >         break;
> >       }
> >     }
> >     if (isset($bbcode)) {
> >       $message->message = "\n\n[quote=". $message->recipient .']'.
> > $message->message .'[/quote]';
> >     }
> >     else {
> >       $message->message = "\n\n\n". str_replace("\n", "\n> ", "\n".
> > $message->message);
> >     }
> >   }
> >
> >   if (isset($_SESSION['recipients'])) {
> >     $recipient = implode(', ', $_SESSION['recipients']);
> >     unset($_SESSION['recipients']);
> >   }
> >
> >
> >   $form = array('preview' => array());
> >
> >   $form['thread'] = array('#type' => 'value', '#value' => isset
> > ($message->thread) ? $message->thread : 0);
> >   $form['header']['#theme'] = 'privatemsg_new_msg_header';
> >   $form['header']['recipient'] = array(
> >     '#type' => 'hidden',
> >     '#title' => t('Purchase'),
> >     '#description' => t('Separate multiple names with commas.'),
> >     '#default_value' => isset($recipient) ? $recipient : $message-
> > >recipient,
> >     '#autocomplete_path' => 'privatemsg/autocomplete',
> >     '#size' => 50,
> >     '#maxlength' => 1000,
> >   );
> >
> >   $form['header']['subject'] = array(
> >     '#type' => 'textfield',
> >     '#title' => t('Subject'),
> >     '#default_value' => $message->subject,
> >     '#size' => 50,
> >     '#maxlength' => 64,
> >   );
> >
> >   $form['privatemsgbody'] = array(
> >     '#type' => 'textarea',
> >     '#title' => t('Message'),
> >     '#default_value' => $message->message,
> >     '#cols' => 80,
> >     '#rows' => 6,
> >   );
> >   $form[] = filter_form($message->format);
> >   $form[] = array(
> >     '#type' => 'submit',
> >     '#value' => t('Preview')
> >   );
> >   $form[] = array(
> >     '#type' => 'submit',
> >     '#value' => t('Send private message')
> >   );
> >   $form['#after_build'] = array('_privatemsg_new_preview');
> >
> >   drupal_add_js(drupal_get_path('module', 'privatemsg') .'/
> > privatemsg.js');
> >
> >   return $form;
> > }
> >
> > Any help to get this modification done would be greatly appreciated!
> >
> > Thanks,
> >
> > Antoine
> >
> > --
> > [ Drupal support list | http://lists.drupal.org/ ]
> >
> > --
> > [ Drupal support list | http://lists.drupal.org/ ]
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://lists.drupal.org/pipermail/support/attachments/20070810/9ddee162/attachment.htm
>
> ------------------------------
>
> --
> [ Drupal support list | http://list.drupal.org/ ]
>
> End of support Digest, Vol 56, Issue 13
> ***************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20070810/f1bf23bf/attachment-0001.htm 


More information about the support mailing list