I'm mainly wondering if this is possible for me to alter or override on my part, but I also think this is how it should be by deafult. I don't see what purpose the comma serves when I'm not allowing more than 1 recipient.

Comments

The problem is that the autocomplete suggestion knows nothing about that limitation because that limitation comes from a separate module.

Not sure how to properly fix that.

Wouldn't something like this work?

replace:

<?php
 
// Prefix the matches and convert them to the correct form for the
  // autocomplete.
 
$prefix = count($names) ? implode(", ", $names) .", " : '';
 
$suggestions = array();
  foreach (
$themed_matches as $match) {
   
$suggestions[$prefix . $match . ', '] = $match;
  }
?>

with:

<?php
  $suffix
= ', ';
  if (
module_exists('privatemsg_filter')) {
    if (
variable_get('privatemsg_limits_recipients_enabled', FALSE)) {
      global
$user;
     
$amount = _privatemsg_limits_get_amount('recipients_amount', $user);
      if (
$amount == 1) {
       
$suffix = '';
      }
    }
  }
 
// Prefix the matches and convert them to the correct form for the
  // autocomplete.
 
$prefix = count($names) ? implode(", ", $names) .", " : '';
 
$suggestions = array();
  foreach (
$themed_matches as $match) {
   
$suggestions[$prefix . $match . $suffix] = $match;
  }
?>

It seems to work for me.

I actually don't know how to write a patch and I see that you asked me for one in my other issue. It's high time I learn to do so so the next time I'll try to have a patch instead. :)

Creating patches with git is easy, every project has a git instructions local task with specific instructions, see for example http://drupal.org/node/3279/git-instructions/master/nonmaintainer

About the code. Yes, we want something like that. The problem is, I'd like to avoid putting privatemsg_filter specific code into privatemsg.module, we really want to keep them separate.

So what I'd suggest is something like this:

- Add a drupal_alter('privatemsg_autocomplete_suggestions', $suggestions) below that code.
- Document that new hook (hook_privatemsg_autocomplete_suggestions_alter($suggestions) in privatemsg.api.php
- Then, implement that hook in privatemsg_filter.module and remove the trailing ", ". Additionally, you can also add code to verify that there is only the limited amount of suggestions. Example. Even if we stop adding the trailing ", ", People can still add it manually and type something like "userA, us" and Privatemsg will happily suggest another user. privatemsg_limits should only show the last X users in that suggestion list so that when you have configured it to a single recipient, it should replace the existing one.

This might look unecessary complicated at first, but this hook will allow other sites to move their autocomplete customizations into that hook, for example when they are showing a profile image in the autocomplete.

Version:» 6.x-2.x-dev
Category:support» feature
Status:Active» Needs work