I had user profiles configured to includes names, so I wanted the Send module to also check the user profile. here's some code I added to _send_form in send.module, at line 207 (just after the call to _send_crm_contact:
// Alternatively, try looking in the User's profile
profile_load_profile($user);
// var_dump($user);
if (empty($sender['first_name'])) {
if (isset($user->profile_firstname)) {
$sender['first_name'] = $user->profile_firstname;
}
}
if (empty($sender['last_name'])) {
if (isset($user->profile_lastname)) {
$sender['last_name'] = $user->profile_lastname;
}
}
The easiest way for me to do it was to hardcode the name of the profile field I had added, but maybe someone out there can make this more elegant by establishing a settings parameter and using that instead.
Comments
Comment #1
allie mickaI'm sure you understand why this couldn't be the default behavior of send, and I think it might be inflexible to do per-field settings like this.
I am marking this issue as a duplicate of http://drupal.org/node/72161 , because I think we can work out some kind of a language for default and optional tokens.
We could set sensible defaults as the "fullname" token (e.g. the username), and then allow separate modules to override this.
Thanks!
Comment #2
mandclu commentedI guess I thought you could just name a profile field on the settings page that the module could check for each of the name fields.
Naturally, I do get why this isn't for everyone, but I found it useful, so I thought I'd share. This is the kind of thing I'd rather tackle in a separate module, but I couldn't think of a way to do it.
I would like to add a dropdown of other users to use as recipients, I don't know if that also falls into your tokens discussion. I can sort of see how that one might work as an add-on module, at least in terms of altering the form, though I do think I might have to alter the Send modules form processing, at least a little.
Comment #3
allie mickaI'm not inherently opposed to this, but I would prefer to exhaust the more systematic ways of approaching this first. And I think this is part of the larger token problem, so I wanted to start there.
waaay back in the 4.6 days when I originally wrote send, one design goal was to have a dropdown list of recipients to whom you've previously initiated messages. This got dropped along the way.
As seen in the news module, it's pretty simple to write a submodule with different form behavior ( I would love to see a petition module that uses send's internal tracking!). Send is reasonably flexible about receiving form data (e.g. it will deliver to recipient_mail or an array called recipients ). That said, I'm open to making changes that facilitate sub-modules.
Comment #4
mandclu commentedCould a separate module alter the $sender variable before it is returned by Send's _send_crm_contact variable? I guess that would be the most elegant way, but I'm not 100% sure how to do that. Would your function have to check for other modules' modifiers?
As far as an add-on for the user list, maybe all that is need is some logic to handle uids as well as the standard info. Again, I don't know if it needs to be restructured so that an add-in can provide that logic.
I'm still very much learning my way with Drupal, and appreciate whatever guidance you can provide on how to do things in the most constructive way.